#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#include <time.h>
#include <string.h>
#include <math.h>

////////////////////////////////////
typedef unsigned char uint8_t;
typedef unsigned int uint16_t;
typedef unsigned long int uint32_t;

typedef unsigned char uint8;
typedef unsigned int uint16;
typedef unsigned long int uint32;

typedef signed char int8_t;
typedef signed int int16_t;
typedef signed long int int32_t;

typedef signed char int8;
typedef signed int int16;
typedef signed long int int32;
///////////////////////////////////////

#include <time.h>
typedef struct
{
    char *arg1;
    char *arg2;
    char *arg3;

} dq_vcmd_param_t;
static dq_vcmd_param_t dq_vcmd_param = {0};

void code_29()
{
    char txt[] = {"123123"};
    dq_vcmd_param.arg1 = (char *)malloc(sizeof(txt));
    strcpy(dq_vcmd_param.arg1, txt);
    printf("%s\n", dq_vcmd_param.arg1);
    free(dq_vcmd_param.arg1);
}
void code_28()
{
    char phone_num[] = {"17377342903"};
    printf("len[%d]\n", (int)strlen(phone_num));

    for (int i = 0; i < 100; i++)
    {
        printf("[%d]%d ", i, i % 2);
    }

    char num_buf[5] = {0};
    itoa(102, num_buf, 10);
    printf("\nnum_buf[%s]\n", num_buf);
}

typedef struct
{
    char buf[4];

} text_t;
text_t *text = NULL;
void code_27()
{
    int a = 0x01;

    printf("%2x %02x\n", a, a);

    text_t *buf = malloc(sizeof(text_t) * 50);
    memset(buf, 1, sizeof(text_t) * 50);

    int size = sizeof(buf) * 50 / sizeof(text_t);
    printf("size[%d] [%s]\n", size, buf);
    free(buf);
    buf = NULL;
}
void code_26()
{
    char txt = 0x49;
    int num = 0;
    memcpy((char *)&num, &txt, sizeof(txt));
    printf("%d\n", num);
}
void code_25()
{
    int buf = 0;
    char txt = 0xFF;
    memcpy((char *)&buf, &txt, sizeof(txt));
    printf("%d\n", buf);
}

#define GAP_ADTVYPE_FLAGS 0x01                     //!< Discovery Mode: @ref GAP_ADTYPE_FLAGS_MODES
#define GAP_ADVTYPE_16BIT_MORE 0x02                //!< Service: More 16-bit UUIDs available
#define GAP_ADVTYPE_16BIT_COMPLETE 0x03            //!< Service: Complete list of 16-bit UUIDs
#define GAP_ADVTYPE_32BIT_MORE 0x04                //!< Service: More 32-bit UUIDs available
#define GAP_ADVTYPE_32BIT_COMPLETE 0x05            //!< Service: Complete list of 32-bit UUIDs
#define GAP_ADVTYPE_128BIT_MORE 0x06               //!< Service: More 128-bit UUIDs available
#define GAP_ADVTYPE_128BIT_COMPLETE 0x07           //!< Service: Complete list of 128-bit UUIDs
#define GAP_ADVTYPE_LOCAL_NAME_SHORT 0x08          //!< Shortened local name
#define GAP_ADVTYPE_LOCAL_NAME_COMPLETE 0x09       //!< Complete local name
#define GAP_ADVTYPE_POWER_LEVEL 0x0A               //!< TX Power Level: 0xXX: -127 to +127 dBm
#define GAP_ADVTYPE_OOB_CLASS_OF_DEVICE 0x0D       //!< Simple Pairing OOB Tag: Class of device (3 octets)
#define GAP_ADVTYPE_OOB_SIMPLE_PAIRING_HASHC 0x0E  //!< Simple Pairing OOB Tag: Simple Pairing Hash C (16 octets)
#define GAP_ADVTYPE_OOB_SIMPLE_PAIRING_RANDR 0x0F  //!< Simple Pairing OOB Tag: Simple Pairing Randomizer R (16 octets)
#define GAP_ADVTYPE_SM_TK 0x10                     //!< Security Manager TK Value
#define GAP_ADVTYPE_SM_OOB_FLAG 0x11               //!< Secutiry Manager OOB Flags
#define GAP_ADVTYPE_SLAVE_CONN_INTERVAL_RANGE 0x12 //!< Min and Max values of the connection interval (2 octets Min, 2 octets Max) (0xFFFF indicates no conn interval min or max)
#define GAP_ADVTYPE_SIGNED_DATA 0x13               //!< Signed Data field
#define GAP_ADVTYPE_SERVICES_LIST_16BIT 0x14       //!< Service Solicitation: list of 16-bit Service UUIDs
#define GAP_ADVTYPE_SERVICES_LIST_128BIT 0x15      //!< Service Solicitation: list of 128-bit Service UUIDs
#define GAP_ADVTYPE_SERVICE_DATA 0x16              //!< Service Data - 16-bit UUID
#define GAP_ADVTYPE_PUBLIC_TARGET_ADDR 0x17        //!< Public Target Address
#define GAP_ADVTYPE_RANDOM_TARGET_ADDR 0x18        //!< Random Target Address
#define GAP_ADVTYPE_APPEARANCE 0x19                //!< Appearance
#define GAP_ADVTYPE_ADV_INTERVAL 0x1A              //!< Advertising Interval
#define GAP_ADVTYPE_LE_BD_ADDR 0x1B                //!< LE Bluetooth Device Address
#define GAP_ADVTYPE_LE_ROLE 0x1C                   //!< LE Role
#define GAP_ADVTYPE_SIMPLE_PAIRING_HASHC_256 0x1D  //!< Simple Pairing Hash C-256
#define GAP_ADVTYPE_SIMPLE_PAIRING_RANDR_256 0x1E  //!< Simple Pairing Randomizer R-256
#define GAP_ADVTYPE_SERVICE_DATA_32BIT 0x20        //!< Service Data - 32-bit UUID
#define GAP_ADVTYPE_SERVICE_DATA_128BIT 0x21       //!< Service Data - 128-bit UUID
#define GAP_ADVTYPE_3D_INFO_DATA 0x3D              //!< 3D Information Data
#define GAP_ADVTYPE_MANUFACTURER_SPECIFIC 0xFF     //!< Manufacturer Specific Data: first 2 octets contain the Company Identifier Code followed by the additional manufacturer specific data

void code_24()
{
    //    char test_data[500] = {0x02,0x01,0x06,0x1B,0xFF,0x57,0x01,0x02,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x03,0xD9,0x7F,0x4B,0xEB,0xFA,0xBC,0x10,0x09,0x4D,0x69,0x20,0x53,0x6D,0x61,0x72,0x74,0x20,0x42,0x61,0x6E,0x64,0x20,0x36,0x03,0x02,0xE0,0xFE,0x07,0x16,0xE0,0xFE,0x61,0x10,0x00,0x00};

    // unsigned char test_data[500] = {0x02,0x01,0x06,0x19,0xFF,0x00,0xFF,0xED,0x00,0x5F,0xFE,0x5B,0xB0,0x5D,0xA8,0xF9,0x06,0x00,0x31,0x81,0x9E,0xF1,0x89,0x0D,0xA6,0xC8,0x4F,0xBD,0xE4,0x0B,0x09,0x55,0x66,0x61,0x63,0x65,0x2D,0x42,0x4C,0x54,0x31,0x03,0x03,0xE7,0xFC,0x05,0x12,0x50,0x00,0x20,0x03,0x02,0x0A,0xC5};

    unsigned char test_data[] = {0x02, 0x01, 0x04, 0x1B, 0xFF, 0x57, 0x01, 0x02, 0xFF, 0xFF, 0xFF,
                                 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x02, 0xFD,
                                 0x08, 0xCB, 0xDE, 0x9D, 0x56, 0x10, 0x09, 0x4D, 0x69, 0x20, 0x53, 0x6D, 0x61, 0x72, 0x74,
                                 0x20, 0x42, 0x61, 0x6E, 0x64, 0x20, 0x36, 0x03, 0x02, 0xE0, 0xFE, 0x07, 0x16, 0xE0, 0xFE,
                                 0x7A, 0x11, 0x00, 0x00};
    int data_cout = 0;

    while (data_cout < sizeof(test_data))
    {
        uint8_t len = test_data[data_cout];
        uint8_t data_type[2] = {0};
        uint8_t data_buf[32] = {0};

        memcpy(data_type, test_data + data_cout + 1, 1);
        //        printf("data_cout[%d] len[%d] data_type[%02x]\n",data_cout,len,data_type[0]);

        memcpy(data_buf, test_data + data_cout + 2, len - 1);

        // ��ȡ����
        if (data_type[0] == GAP_ADVTYPE_LOCAL_NAME_SHORT)
        {
            printf("LOCAL_NAME_SHORT:[%s]\n", data_buf);
        }

        if (data_type[0] == GAP_ADVTYPE_LOCAL_NAME_COMPLETE)
        {
            printf("LOCAL_NAME_COMPLETE:[%s]\n", data_buf);
        }

        // ��ȡUUID
        if (data_type[0] == GAP_ADVTYPE_SERVICE_DATA)
        {
            printf("SERVICE_DATA:[");
            for (int i = 0; i < len - 1; i++)
            {
                printf("%02X", data_buf[i]);
            }
            printf("]\n");
        }

        if (data_type[0] == GAP_ADVTYPE_16BIT_MORE)
        {
            printf("16BIT_MORE:[");
            for (int i = 0; i < len - 1; i++)
            {
                printf("%02X", data_buf[i]);
            }
            printf("]\n");
        }

        // ��ȡ��������
        if (data_type[0] == GAP_ADVTYPE_MANUFACTURER_SPECIFIC)
        {
            printf("MANUFACTURER_SPECIFIC:[");
            for (int i = 0; i < len - 1; i++)
            {
                printf("%02X", data_buf[i]);
            }
            printf("]\n");
        }

        if (data_type[0] == GAP_ADVTYPE_LE_BD_ADDR)
        {
            printf("LE_BD_ADDR:[");
            for (int i = 0; i < len - 1; i++)
            {
                printf("%02X", data_buf[i]);
            }
            printf("]\n");
        }

        if (data_type[0] == GAP_ADVTYPE_LE_ROLE)
        {
            printf("LE_ROLE:[");
            for (int i = 0; i < len - 1; i++)
            {
                printf("%02X", data_buf[i]);
            }
            printf("]\n");
        }

        if (data_type[0] == GAP_ADTVYPE_FLAGS)
        {
            printf("FLAGS:[");
            for (int i = 0; i < len - 1; i++)
            {
                printf("%02X", data_buf[i]);
            }
            printf("]\n");
        }

        if (data_type[0] == GAP_ADVTYPE_3D_INFO_DATA)
        {
            printf("3D_INFO_DATA:[");
            for (int i = 0; i < len - 1; i++)
            {
                printf("%02X", data_buf[i]);
            }
            printf("]\n");
        }

        if (data_type[0] == GAP_ADVTYPE_POWER_LEVEL)
        {
            printf("POWER_LEVEL:[");
            for (int i = 0; i < len - 1; i++)
            {
                printf("%02X", data_buf[i]);
            }
            printf("]\n");
        }

        if (data_type[0] == GAP_ADVTYPE_SLAVE_CONN_INTERVAL_RANGE)
        {
            printf("SLAVE_CONN_INTERVAL_RANGE:[");
            for (int i = 0; i < len - 1; i++)
            {
                printf("%02X", data_buf[i]);
            }
            printf("]\n");
        }

        if (data_type[0] == GAP_ADVTYPE_LE_BD_ADDR)
        {
            printf("LE_BD_ADDR:[");
            for (int i = 0; i < len - 1; i++)
            {
                printf("%02X", data_buf[i]);
            }
            printf("]\n");
        }
        if (data_type[0] == GAP_ADVTYPE_ADV_INTERVAL)
        {
            printf("ADV_INTERVAL:[");
            for (int i = 0; i < len - 1; i++)
            {
                printf("%02X", data_buf[i]);
            }
            printf("]\n");
        }

        data_cout = data_cout + len + 1;
        //        printf("data_cout[%d]....\n",data_cout);
    }
}

void code_23()
{

    text = (text_t *)malloc(sizeof(text_t) * 10);
    memset(text, 0, sizeof(text_t) * 10);
    for (int i = 0; i < 10; i++)
    {
        printf("[%d][%s]\n", i, text[i].buf);
    }

    char n[1] = {12};
    printf("%d\n", n[0]);
}
void code_22()
{
    char buf1[] = {"BDADDR: 0x7560363232C3   "}, buf2[] = {"BDADDR: 0x"};
    int x = strspn(buf1, buf2);

    printf("%d\n", x);
    printf("[%s]\n", buf1 + x);

    char txt[20] = {0};
    strncpy(txt, buf1 + x, 12);
    printf("txt[%s]\n", txt);
}
void code_21()
{
    char buf1[] = {"BDADDR: 0x7560363232C3   "}, buf2[] = {"BDADDR: 0x"};
    char *txt = strpbrk(buf1, buf2);
    printf("[%s]\n", txt + sizeof(buf2) - 1);

    char txt2[20] = {0};
    strncpy(txt2, txt + sizeof(buf2) - 1, 12);

    printf("txt2[%s]\n", txt2);
}

void printf_char_test(char *buf)
{
    printf("%s\n", buf);
}

void code_20()
{
    char buf[20] = {"AAAABBBABA"};
    char buf1[20] = {0};
    strncpy(buf1, buf + 2, 5);
    //    sprintf(buf1,"%s",buf+4);
    printf_char_test(buf1);
}
void code_19()
{
    char buf[] = {"dasdsada�����ǰ���"};
    printf("%s\n", buf);
    char buf1[50] = {0};
    for (int i = 0; i < 50; i++)
    {
        sprintf(buf1, "%sWW", buf);
    }
    printf("%s\n", buf1);
    if (strncmp(buf, "d", 1) == 0)
    {
        printf("OK\n");
    }

    printf("%d\n", (int)strlen(buf));
}
void code_18()
{
    char buf[50] = {0};
    sprintf(buf, "%s", "1234");
    for (int i = 0; i < 50; i++)
    {
        if (memcmp(buf + i, "\0", 1) == 0)
        {
            printf("curr i [%d]", i);
            //            printf("[%s]",arg);
            return;
        }
    }
}
#define AA_SPACE sizeof(int)
char *del_A(char *para)
{
    //    char buf[64] = {0};
    printf("para:%s\n", para);
    //    sprintf(buf,"%s",para+1);
    //    printf("buf:%s\n",buf+1);

    //    memcpy(buf,para,sizeof(buf));
    return para;
}
void code_17()
{
    char cmp_buf1[6] = {0x12, 0x13, 0x14, 0x15, 0x16, 0x17};
    char cmp_buf2[6] = {0x12, 0x13, 0x14, 0x15, 0x16, 0x17};

    printf("[%x%x%x%x%x%x] : [%x%x%x%x%x%x]\n", cmp_buf1[0], cmp_buf1[1], cmp_buf1[2], cmp_buf1[3], cmp_buf1[4], cmp_buf1[5],
           cmp_buf2[0], cmp_buf2[1], cmp_buf2[2], cmp_buf2[3], cmp_buf2[4], cmp_buf2[5]);
    if (memcmp(cmp_buf1, cmp_buf2, 6) == 0)
    {
        printf("ok\n");
    }
    else
        printf("bad\n");

    printf("%.3f%%\n", 1.23456);

    float val = 3780;

    printf("%0.3f\n", ((4400 - val) / (4400 - 3300)) * 100);
}
void code_16()
{
    //    char buff[64] = {0};
    //    sprintf(buff,"%s",del_A("A456789"));
    //    printf("buff:[%s]\n",buff);

    char aa[64] = {0};
    sprintf(aa, "%s", "ALKJ");
    del_A(aa + 1);
}

void code_15()
{
    //    char *buf_1 = (char *)malloc(100);
    FILE *test_file = fopen("D:/12.txt", "r");
    char
        bit,
        bit_buf[500] = {0};

    for (int i = 0; i < 200; i++)
    {
        bit = fgetc(test_file);

        //        printf("%c",bit);
    }
    fgets(bit_buf, 500, test_file);

    fclose(test_file);
}
void strcpy_test(char *a)
{

    char *buf1 = (char *)malloc(sizeof(100));
    strcpy(buf1, a);
    printf("%s\n", buf1);
    printf("%p", buf1);
    free(buf1);
}
void code_14()
{
    int count = 1;
    for (int i = count; i != 0; i--)
    {
        printf("%d\n", i);
    }

    char buf1[] = "01234";
    printf("%c%c%c\n", buf1[0], buf1[1], buf1[2]);

    strcpy_test("QQ");
    //    return 0;
}

int add(void);

typedef struct
{
    int number;
    char *name;
    int list;

} struct_t;

#define BST 1
#define CCT 8

char *my_send(void)
{
    char *b = "ASD";
    printf("%s\n", b);

    return "ASDAFF";
}

void copy(char *aa)
{
    char *a = "DDA";
    strcpy(aa, a);
}
void code_13()
{
    float arc_x = 1000, arc_y = 1533,
          //    arc_z = 8422,
        s = 3.1415926, arc;
    arc = atan2(arc_x, arc_y) * 180 / s;
    printf("arc: %f\n", arc);

    short a = 65535;
    printf("%d\n", a);
}
void code_12()
{
    //    char buf1[10] = "ABCD";
    //    char buf2[10] = {0};//"ABCD";
    //
    //
    //    memcpy(buf2,"ABCD",sizeof(buf2));
    //    printf("buf1 [%s] buf2 [%s]\n",buf1, buf2);
    //
    //
    //    if(memcmp(buf1,buf2,sizeof(buf2)) == 0)
    //    {
    //        printf(">>\n");
    //    }
    //    else printf("<<\n");

    // float a = 1.123456,fz;
    // short b = 17360;
    //
    // fz = (float)b / 2048;
    //
    // printf("%.4f,%.4f",a,fz);
}
void code_11()
{
    //    int a = 0x12345678;
    //
    //    unsigned int write_addr = 0x12345678;
    //    int t_write_addr = (write_addr << 24 | write_addr >> 8 << 16 | write_addr >> 16 << 8 | write_addr >> 24);
    //    printf("[%02x] [%d]\n",t_write_addr,sizeof("AAAAA"));
    //
    char *a = "0123456789";
    char *b = NULL;
    b = (char *)malloc(10);
    memset(b, 0, 10);
    memcpy(b, a + 2, sizeof(a));
    printf("%c", b[1]);
    free(b);

    //    char b[20] = {0};
    //    for(int i= 0;i < 20; i++)
    //    {
    ////        sprintf(b[i],"%d",12);
    //        int aa = i;
    //        memcpy(b+i,&aa,1);
    //        printf("%d\t",b[i]);
    //    }

    //    return 0;
}
void code_10()
{
#define CHAT_MAX_WORD 10

    char content[500] = {0};
    sprintf(content, "�Ҿն��϶�������432423���������׶��˿����͵���������43254325���˿Ƽ������ɼ�����4325342�����ҵ���43254325�������̿�");

    int count = sizeof(content) / sizeof(content[0]);

    printf("%s %d\n", content, count);
    int count_max = count + count % CHAT_MAX_WORD;
    printf("%d\n", count_max);

    char *temp = (char *)malloc(count_max);
    memset(temp, 0, count_max);
    //    printf("%s",temp);

    int j = 0;
    for (int i = 0; i < count; i++)
    {

        if (i % CHAT_MAX_WORD == 0 && i != 0)
        {
            temp[j] = '\n';
            temp[j + 1] = content[i];
            j += 2;
        }
        else
        {
            temp[j] = content[i];
            j++;
        }
    }

    printf("%s%d", temp, count_max);
    free(temp);
    //    return 0;
}
void code_9()
{

    char *a = "ABCD"
        //    , *b = "BBBB"
        ;

    if (a[1] == 'B')
    {
        printf("[%c]\n", a[3]);
    }
    else
        printf("fail\n");
    printf("%c\n", a[0]);

    //    return 0;
}
void code_8()
{

    long int timestamp = 1640074149;
    long int year, month,
        //     day,
        //     hour,
        //    min,
        //    sec,
        common_year, leap_year;
    long int
        //    temp_count_year,
        temp_count_1,
        temp_count_2;

    for (int year_i = 1970; year_i > 0; year_i++)
    {

        if (year_i % 400 == 0 && year_i % 4 == 0 && year_i % 100 != 0)
        {
            leap_year++;

            temp_count_1 = leap_year * 366 * 24 * 60 * 60 + common_year * 365 * 24 * 60 * 60;
            if (temp_count_1 >= timestamp)
            {
                year_i = -1;
                leap_year--;
                year = 1970 + leap_year;
                temp_count_1 = leap_year * 366 * 24 * 60 * 60 + common_year * 365 * 24 * 60 * 60;
                printf(" comm >>> leap_year [%ld] common_year [%ld] temp_count_1 [%ld]\n", leap_year, common_year, temp_count_1);

                continue;
            }
        }
        else
        {
            common_year++;

            temp_count_1 = leap_year * 366 * 24 * 60 * 60 + common_year * 365 * 24 * 60 * 60;
            if (temp_count_1 >= timestamp)
            {
                year_i = -1;
                common_year--;
                year = 1970 + common_year;
                temp_count_1 = leap_year * 366 * 24 * 60 * 60 + common_year * 365 * 24 * 60 * 60;
                printf("leap >>> leap_year [%ld] common_year [%ld] temp_count_1 [%ld]\n", leap_year, common_year, temp_count_1);

                continue;
            }
        }
    }

    printf("common_year [%ld] leap_year [%ld] year [%ld] temp_count_1 [%ld]\n", common_year, leap_year, year, temp_count_1);
    int month_com[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    temp_count_2 = temp_count_1;
    for (int month_i = 0; month_i < 12; month_i++)
    {
        temp_count_2 += month_com[month_i] * 60 * 60 * 24;
        if (temp_count_2 > temp_count_1)
        {

            month_i--;
            if (month_i <= 0)
            {
                month = 1;
            }
            else
                month += 1;
            temp_count_2 -= month_com[month_i] * 60 * 60 * 24;
            printf("month [%d] temp_count_2 [%d]\n", month, temp_count_2);
            month_i = 15;
            continue;
        }
    }
    time_t timea;
    time(&timea);
    printf("timea %d\n", timea);
    printf("%s\n", ctime(&timea));
    //    printf("%ld\n",year + 1970 );
    //    return 0;
}

void code_7()
{
    char *a = "GGGF";
    a = my_send();

    printf("%s\n", a);

    char tet[64] = "";
    strcpy(tet, a);

    //    char *tet = "";           //��������ʹ��ָ���ַ���
    //    copy(tet);
    printf("[%s]\n", tet);
}
void code_6()
{
    //    FILE *p = fopen("D:/12.txt","a");
    //    if(p == NULL)
    //    {
    //        printf("��ʧ��\n");
    //    }
    //    char char_a[] = "sdaaaaaaaaa\n";
    //    fputs(char_a,p);
    //
    //    fclose(p);

    FILE *open_file = fopen("D:/12.txt", "r");
    char file_char[128];

    for (int i = 0; i < 100; i++)
    {

        file_char[i] = fgetc(open_file);
    }
    printf("%s", file_char);

    fclose(open_file);

    //    return 0;
}
void code_5()
{
    int a = -2;
    if (-51 > a)
    {
        printf("shide \n");
    }
    else if (-41 > a)

    {
        printf("bushi \n");
    }
    else if (-31 > a)
    {
        printf("bushi1 \n");
    }
    else if (-21 > a)
    {
        printf("bushi 2\n");
    }
    else if (-1 > a)
    {
        printf("bushi 3\n");
    }
    else
        printf("xiecuo \n");
}
void battery_c()
{
    unsigned int vol = 43287;

    unsigned int vol_min = 3300, vol_max = 4500, vol_bat = 0;
    float vol_param = 0;
    vol_param = ((float)vol - vol_min) / (vol_max - vol_min);
    printf("%f\n", vol_param);
    vol_bat = vol_param * 100;
    printf("%d\n", vol_bat);
    switch (vol_bat / 10)
    {
    case 0:
    case 1:
        printf("������\n");
        break;
    case 2:
    case 3:
        printf("������\n");
        break;
    case 4:
    case 5:
        printf("����һ��\n");
        break;
    case 6:
    case 7:
    case 8:
        printf("��������\n");
        break;
    case 9:
    case 10:
        printf("������\n");
        break;
    default:
        printf("����쳣�������\n");
        break;
    }
}

void char_strcat()
{
    char key[128] = "";
    char *key_char_1 = "for wifi ";

    strcat(key, "NN ");
    *key = 0;
    strcat(key, key_char_1);
    strcat(key, "ok ");

    printf("%s", key);
}
void keyboard_matrix()
{
    static char *text_select_map[][23] = //{'1','2'}
        {
            {",", ".", "?", "!", ""}, // symbol 0
            {"-", "+", "*", "/", ""},
            {"(", ")", "[", "]", ""},
            {"<", ">", "~", "^", ""},
            {":", ";", "\\", "\"", ""},
            {"&", "|", "@", "#", ""},
            {"_", "{", "", "", ""},
            {"}", "$", "`", "=", ""},
            {"a", "b", "c", "", ""}, // lc 8
            {"d", "e", "f", "", ""},
            {"g", "h", "i", "", ""},
            {"j", "k", "l", "", ""},
            {"m", "n", "o", "", ""},
            {"p", "q", "r", "s", ""},
            {"t", "u", "v", "", ""},
            {"w", "x", "y", "z", ""},
            {"A", "B", "C", "", ""}, // uc 16
            {"D", "E", "F", "", ""},
            {"G", "H", "I", "", ""},
            {"J", "K", "L", "", ""},
            {"M", "N", "O", "", ""},
            {"P", "Q", "R", "S", ""},
            {"T", "U", "V", "", ""},
            {"W", "X", "Y", "Z", ""}

        };

    int i = 0,
        n = 1;
    printf("%c,%d", text_select_map[i][n], sizeof(text_select_map[i][n]));
}

// void remainder(void)
//{
//     printf("************\n");
//     for(int test = 0; test < 100; test++)
//         printf("source��%d\t ~2: %d\t ~3: %d\t ~4: %d\t ~5: %d\t ~6: %d\t ~7: %d\t ~8: %d\t ~9: %d\n ",test,test%2,test%3,test%4,test%5,test%6,test%7,test%8,test%9);
//     printf("************\n");
//
//     char *ss = "dsadasd";
//     printf("%s\n",ss);
// }

void get_char(void)
{
    // remainder();
    char *tt = "ASDasdasdassad";
    //    char txt[] = "aSD";
    //    char *txt = tt;

    for (int i = 0; i < strlen(tt); i++)
    {
        if (tt[i] != '\0')
        {
            printf("%c\n", tt[i]);
        }
        else
            printf("fail\n");
    }
}

static struct_t *ch_1;
int get_struct(struct_t **emm)
{

    *emm = ch_1;

    //    printf("ch_1[0] :%s\n",ch_1[0].name);   //OK
    //    printf("emm[0] :%s\n",emm[0].name);   //OK
    printf(">>>2<<emm :0x%X\n", emm);   // OK
    printf(">>>3<<ch_1 :0x%X\n", ch_1); // OK

    return 0;
}
void struct_1(void)
{
    static struct_t ch[2] = {{12, "Lihua", 21}, {11, "Libai", 11}};
    ch_1 = ch;
    //    printf("ch[0] :%s\n",ch[0].name);           //OK
    //    printf("ch_1[0] :%s\n",ch_1[0].name);       //OK
    //    printf(">>>1<<<ch :0x%X\n",ch);   //OK
}

int code_1(void)
{
    printf("Hello world!\n");

    int *aa, *add_function, *p_struct;

    int i[10] = {1, 2, 3, 4, 5, 6, 7};

    struct_t struct_a;

    aa = NULL;
    aa = (int *)malloc(AA_SPACE);
    if (aa != NULL)
    {

        memset(aa, 0, AA_SPACE); // initial space 'aa' use " 0 "
        aa = i;

        printf("i[10] Դ��ַ  = %p\n", i);
        printf("ֵ = %d\t ָ������ָ���ַ: %p\n", *aa, aa);
        // printf("%p\t %d\n",aa,AA_SPACE);

        // aa = (int *)realloc(aa,20);
        printf("%p\n", aa);
    }
    else
        printf("�ռ�����ʧ�ܣ�\n");

    add_function = NULL;
    add_function = (int *)malloc(sizeof(int) * 500);
    if (add_function != NULL)
    {
        add_function = (int *)add();
        printf("add_function �����%d\t add = %p\n", add_function, &add_function);
    }
    else
        printf("�ռ�����ʧ�ܣ�\n");

    struct_a.number = 12;
    struct_a.name = "Hello World";
    struct_a.list = 7;

    p_struct = NULL;
    p_struct = (int *)(struct_t *)malloc(sizeof(struct_t));
    if (p_struct != NULL)
    {
        memset(p_struct, 0, sizeof(struct_a));
        p_struct = (int *)&struct_a;

        printf("\n\nָ��ṹ���ָ��ĵ�ַ:\t%p\n", p_struct);
        // p_struct = *struct_a.name;

        printf("%d\t    %p\t    %s\t    %p\t    %d\t    %p\n\n", struct_a.number, &struct_a.number, struct_a.name, &struct_a.name, struct_a.list, &struct_a.list);

        printf("%d\t    %p\t    ", (*p_struct), p_struct);
        printf("%s\t    %p\t    ", (*(p_struct + 2)), (p_struct + 2));
        printf("%d\t    %p\n    ", (*(p_struct + 4)), (p_struct + 4));
        //        printf("pointer -> struct_a.name = %s\t pointer -> struct_a.name add = %X\n",p_struct-sizeof(struct_a.name[0])*20,p_struct-sizeof(struct_a.name[0])*20);

        for (int i = 5; i < sizeof(struct_a); i++)
        {
            printf("%d %10d\t    %10p\n    ", i, (*(p_struct + i)), (p_struct + i));
        }

        printf("\n\n%d\t", sizeof(int));
        printf("%d\t", sizeof(char) * 2);
    }
    else
        printf("�ռ�����ʧ�ܣ�\n");

    printf("\n\nFree Space : \n");
    free(p_struct);
    free(add_function);
    free(aa);
    printf("OK!\n");

    return 0;
    return 0;
}

void code_2(void)
{
    char *a[] = {"asdasdsadasdasd", "WWWAAA", "���"};

    printf("*a[] : %s\n", *(a + 2));

    char *word1;
    char word[] = {"ASD���ż��"};

    word1 = word;

    printf("word : %s\n", word1);
}
int add(void)
{
    int x = 1, y = 2;
    printf("\n\nָ�������ָ�룺\nadd result = ");
    return x + y;
}
//
// void code_3(void)
//{
//    struct_t aa = {12, "CHAER", 9};
//    printf("%d %s\n", aa.number, aa.name);
//
//    time_t time1, time2;
//    struct tm *info;
//
//    localtime(&time1);
//
//    time(&time1);
//    gmtime(&time2);
//    //��ʾʱ���ַ���
//    printf("ctime :%s", ctime(&time1));
//    printf("******localtime :%s", asctime(localtime(&time1)));
//    //��ʾʱ����
//    info = gmtime(&time1);
//    printf("\n��ǰ������ʱ�ӣ�\n");
//    printf("�׶أ�%2d:%02d\n", (info->tm_hour + BST) % 24, info->tm_min);
//    printf("�й���%2d:%02d\n", (info->tm_hour + CCT) % 24, info->tm_min);
//
//    char *name_1 = "nihao";
//    char *ad[] = {"sda", " ss", "ss ", "ss ", "dsadasd", ""};
//    printf("%s\n", name_1);
//
//    printf("��Ա����%d", sizeof(ad) / sizeof(ad[0]));
//
//    printf(":::::%d", 999916011 / 1000);
//
//    struct timeb time_f;
//    while (0)
//    {
//        // printf("%d\n",time2);
//        printf("%d\t", time(&time1));
//    }
//}

void code_4()
{

    //    struct_t ch[2] = {{12,"Lihua",21},{11,"Libai",11}};
    //    struct_t *ch_1 = ch;
    //    printf("%s\n",ch+1->name);
    //    printf("%s\n",ch[0].name);
    //    printf("%s\n",ch_1[1].name);

    int aa = 12, *aa_a = &aa;
    int *bb;
    bb = aa_a;
    printf("0x%X %d\n", aa_a, *aa_a);
    printf("0x%X %d\n", bb, bb[0]);

    // code_3();

    printf("********************\n");

    struct_1();

    static struct_t *op = NULL;

    //    printf(">>>-1<<<op :0x%X\n",op);   //OK

    //    op = (struct_t *)malloc(sizeof(struct_t)*100);
    //    memset(op,0,sizeof(struct_t)*100);

    printf(">>>0<<<op :0x%X\n", op); // OK

    get_struct(&op);

    printf(">>>4<<<op :0x%X\n\n", op); // fail

    printf("op[0] :%d\n", op[0].list);
    printf("op[0] :%s\n", op[0].name);
    printf("op[1] :%d\n", op[1].list);
    printf("op[1] :%s\n", op[1].name);
    printf("********************\n");

    //    free(op);
}

typedef enum
{
    TEST1,
    TEST2,
    TEST3,
    TEST4,
    TEST5,
    TEST6,
    TEST7,
    TEST8,
    TEST9,
    TEST10,
    TEST11,
    TEST12,

} test_e;

void code_30()
{
    int a = TEST3;
    char buf[20] = {0};
    memcpy(buf, &a, sizeof(a));
    for (int i = 0; i < sizeof(a); i++)
    {
        printf("%02x ", buf[i]);
    }

    int b = 0;
    memcpy(&b, buf, sizeof(a));
    printf("[%d]b[%d]\n", *buf, b);

    //    int c = 15;
    //    printf("%d",sizeof(*c));
}

void code_31()
{
    char txt1[50] = {"15464313534351"}, txt2[50] = {0};
    for (int i = 0; i < strlen(txt1); i++)
    {
        if (i != 0 && i % 2 == 0)
        {
            strcat(txt2, "-");
            char txt[2] = {0};
            sprintf(txt, "%c", txt1[i]);
            strcat(txt2, txt);
        }
        else
        {

            char txt[2] = {0};
            sprintf(txt, "%c", txt1[i]);
            strcat(txt2, txt);
        }
        printf("%c ", txt1[i]);
    }

    printf("[%s] [%s]\n", txt1, txt2);
    srand(1);
    int ret = rand();
    printf("ret[%d]\n", ret);
}
#define uint32_t unsigned int
typedef struct
{

    uint32_t cf : 5;          /*Color format: See `lv_img_color_format_t`*/
    uint32_t always_zero : 3; /*It the upper bits of the first byte. Always zero to look like a
non-printable character*/

    uint32_t reserved : 2; /*Reserved to be used later*/

    uint32_t w : 11; /*Width of the image map*/
    uint32_t h : 11; /*Height of the image map*/
} lv_img_header_t;
void code_32()
{
    // printf("[%d]\n",1027%1024);
    uint8_t buf[] = {0x05, 0xC0, 0x03, 0x28};
    lv_img_header_t lv_img_header = {0};
    memcpy(&lv_img_header, buf, sizeof(buf));

    char *p = &lv_img_header;

    printf("\n");
    for (int i = 0; i < 4; i++)
    {
        printf("%02X ", p[i]);
    }
    printf("\n");

    printf("h[%d],w[%d] %%\n", lv_img_header.h, lv_img_header.w);

    char *iii = NULL;
    printf("%p\n", iii);
}
void code_33()
{
    FILE *p = NULL;
    p = fopen("05.jpg", "r");
    if (p != NULL)
    {
        char *buf = p;

        for (int i = 0; i < 500; i++)
        {
            printf("%02X ", buf[i]);
        }

        fclose(p);
    }
}
void code_34()
{
    while (1)
    {

        static char flag = 3;
        flag--;
        if (flag % 3 == 0)
        {
            flag = 3;
            return;
        }
        printf("%d\n", flag);
    }
}
void code_35()
{
    char buf[50] = {0};
    printf("%d\n", sizeof(buf));

    for (int i = 1; i < 100; i++)
    {
        printf("[%d]%d ", i, i % 2);
    }
}
void code_36()
{
    char *a = "���ѽ��";
    char buf[20] = {"AA"};
    buf[0] = a[0];
    buf[1] = a[1];
    buf[2] = a[2];
    buf[3] = a[3];
    printf("%s", buf);

    for (int i = 0; i < sizeof(buf); i++)
    {
        printf("%02x %02x \n", buf[i], '\0');
    }

    char *str1 = "dsadsadsdaskosdadso kadadsa";
    char *str2 = strstr(str1, "ok");
    if (str2 == NULL)
    {
        printf("str2 NULL\n");
    }
    else
        printf("%s\n", str2);
}

#define PARSE_MATCH_EN 1
#if PARSE_MATCH_EN
#define MAX_CMDCOUNT 10
char *match_results[MAX_CMDCOUNT] = {0};
int match_result_count = 0;
int count = 0;
int cmd_parse(char *d, int dl)
{
    count++;
    if (d == NULL || dl <= 0)
    {
        return -1;
    }
    printf("input data[%s] len[%d]\n", d, dl);
    int ret_start = 0, ret_mid = 0, ret_end = 0;
    for (int i = 0; i < dl; i++)
    {
        if (d[i] != ' ' && d[i] != '\t')
        {
            ret_start = i;
            break;
        }
    }

    for (int i = ret_start; i <= dl; i++)
    {
        if (d[i] == ' ' || d[i] == '\t' || i == dl)
        {
            ret_mid = i - ret_start;
            break;
        }
    }

    ret_end = ret_start + ret_mid;
    char match_ret[40] = {0};

    if (ret_mid == 0)
    {
        //        memcpy(match_ret,d+ret_start,dl-ret_start);

        return -2;
    }
    else
    {
        memset(match_ret, 0, sizeof(match_ret));
        memcpy(match_ret, d + ret_start, ret_mid);
    }

    printf("[%d][%d][%d] ", ret_start, ret_mid, ret_end);
    printf("--------->>>>>result[%s]<<<<<----------\n", match_ret);

    // save

    if (match_results[match_result_count] == NULL && match_result_count < MAX_CMDCOUNT)
    {
        match_results[match_result_count] = malloc(strlen(match_ret));
        if (match_results[match_result_count] != NULL)
        {
            memset(match_results[match_result_count], 0, strlen(match_ret));
            strcpy(match_results[match_result_count], match_ret);
            match_result_count++;
        }
    }

    if (ret_end > dl)
    {
        return -3;
    }
    else
    {
        int ret = cmd_parse(d + ret_end, strlen(d + ret_end));
        if (ret < 0)
        {
            return -4;
        }
    }
    return -5;
}

void cmd_parse_result_show()
{
    for (int i = 0; i < match_result_count; i++)
    {
        if (match_results[i] != NULL)
        {
            printf("[%d] [%s]\n", i, match_results[i]);

            free(match_results[i]);
        }
    }
    match_result_count = 0;
}

void code_37()
{
    char *a = {"\t 541 `  \t2  5 31 2"};
    //    int len = strlen(a);
    //    for(int i = 0; i < len; i++)
    //    {
    //        printf("%c",a[i]);
    //    }
    //    printf("\n");

    int ret = cmd_parse(a, strlen(a));
    printf("\n\n[%d]\n\n", ret);

    cmd_parse_result_show();
}
#endif

void code_38()
{
    //    char timmm[50] = {"duoqin"};
    //    printf("timmm: %s\n",timmm);
    //    printf("%d \n",atoi(timmm));

    long int num = 16;
    printf("%d %u %ld", num, num, num);
}
typedef struct
{
    uint8 hour;
    uint8 min;
    uint8 sec;
    uint8 year;
    uint8 mon;
    uint8 date;
    uint8 century;
} rtc_time_t;

void code_39()
{
    rtc_time_t t = {0};
    rtc_time_t t1 = {0};

    t.century = 22;
    t.year = 21;
    t.mon = 8;
    t.date = 3;
    t.hour = 14;
    t.min = 51;
    t.sec = 0;

    uint8_t buf1[500] = {0};
    //    uint8_t buf2[500] = {0};
    memcpy(buf1, &t, sizeof(rtc_time_t));
    printf("%d %d %d %d %d %d %d\n", t.century, t.year, t.mon, t.date, t.hour, t.min, t.sec);

    for (int i = 0; i < sizeof(buf1); i++)
    {
        printf("%02X ", buf1[i]);
    }

    int len = sizeof(rtc_time_t);
    printf("\n------------%d\n", len);
    for (int i = 0; i < len; i++)
    {
        uint8_t rtc_a = 0;
        rtc_a = buf1[i];
        printf("%02X ", rtc_a);
        uint8_t *ss = &t1;

        memcpy(ss + i, &rtc_a, sizeof(uint8_t));
    }

    printf(">>>>>>>>>>%d %d %d %d %d %d %d\n", t1.century, t1.year, t1.mon, t1.date, t1.hour, t1.min, t1.sec);
}
void code_40()
{
    printf("uint32_t [%d] uint8_t[%d]\n", sizeof(uint32_t), sizeof(uint8_t));
    uint32_t m = 99999;
    uint8_t *p = NULL;
    int len = sizeof(uint32_t);
    for (int i = 0; i < len; i++)
    {
        p = (uint8_t *)&m;
        printf("%02X ", p[i]);
    }
}
void num_creater()
{
    int single_max_width = 32, single_max_height = 16;
    //    int offset_x = 0, offset_y = 0;

    for (int y = 0; y < single_max_height; y++)
    {
        for (int x = 0; x < single_max_width; x++)
        {
            // 边框
            if (x == 0 || x == single_max_width - 1 || y == 0 || y == single_max_height - 1)
            {

                printf("*");
                continue;
            }

            printf("2");
        }
        printf("\n");
    }
}
void code_41()
{
    num_creater();
    code_40();
    code_37();

    int16_t num = 65535;
    for (int i = 0; i < sizeof(int16_t); i++)
    {
        uint8_t *p = &num;
        printf("%02X ", p[i]);
    }
}
#define PI 3.14159265

void code_42()
{
    //    uint8_t num = 0x2;
    ////    num = num & 0x01;
    //    printf("%02X ",num);
    //
    //
    //    float rx = -10000,ry = -7,rz = 7;
    //    printf("\n%f\n",atan2(rx,rz)*180/PI);
    //
    //    char str1[40] = {"mq1: dadad"};
    //    char *str2 = NULL;

    //    str2 = strstr(str1,": ");
    //    printf("%s\n",str2+2);

    struct tm *temp_time = NULL;
    char time_buf[20] = {0};
    int32_t a = 1660283447;
    //    time_t sec = chat_item->timestamp;
    time_t *ss = NULL;
    time(ss);
    printf("%d\n", time(ss));
    temp_time = gmtime(&a);
    //    temp_time = localtime(&a);
    memset(time_buf, 0, sizeof(time_buf));
    sprintf(time_buf, "%02d-%02d %02d:%02d", temp_time->tm_mon, temp_time->tm_mday, temp_time->tm_hour + 8, temp_time->tm_min);
    printf("%s\n", time_buf);
}
int externbuf[50] = {0};

void code_43()
{
    uint16_t a = 0x400;
    //    a <<= 2;
    printf("%02X \n", a);
    printf("%d", a);

    printf("\n\n%d\n", externbuf[0]);

    uint8_t text[20] = {"nihaoya"};
    printf("sizeof[%d] strlen[%d]\n", sizeof(text), strlen(text));
}
typedef void (*my_cb)(int a, char *b);
static my_cb callback_func = NULL;

typedef struct
{
    int (*cb)(int, char *);

} text_cb_t;
static text_cb_t text_cb;
int out_num_string(int a, char *b)
{
    printf("a[%d] b[%s]\n", a, b);
    return -1;
}
void code_44()
{
    char buf[1024] = {0};
    sprintf(buf, "{\"%s\"}", "nihao ");
    printf("%s\n", buf);

    callback_func = out_num_string;
    text_cb.cb = out_num_string;

    callback_func(12, "nnnn");
    printf("%d\n", text_cb.cb(12, "nnnn"));
    //    system("pause");
    //    system("PATH");
}
void code_45()
{
    int16_t num = 65537;
    int8_t *p = &num;
    printf("%02x %02x\n", p[1], p[0]);
}

// 0x02011A020A0C0AFF4C00100503182EBBBB
uint8_t *hex_format(uint8_t *data, int datalen)
{
    if (data == NULL || datalen <= 0)
    {
        return NULL;
    }

    uint8_t *p = data;
    int len = datalen * 3, offset = 0;
    uint8_t *buf = (uint8_t *)malloc(len);
    if (buf == NULL)
    {
        return NULL;
    }
    memset(buf, 0, len);
    for (int i = 0; i < datalen; i += 2)
    {
        memcpy(buf + offset, "0x", strlen("0x"));
        offset += strlen("0x");

        memcpy(buf + offset, p + i, 1);
        offset += 1;

        memcpy(buf + offset, p + i + 1, 1);
        offset += 1;

        if (i != datalen - 2)
        {
            memcpy(buf + offset, ",", strlen(","));
            offset += strlen(",");
        }

        //        printf("i[%d] offset[%d] %s\n",i,offset,buf);
    }

    return buf;
}

void stringhexarray_to_intarray(uint8_t *src)
{
    if (src == NULL)
    {
        return;
    }

    //    printf("%d ", atoi(src));
}

void code_46()
{
    int a = 100;
    if (!!a)
        printf("write first code a[%d]\n", !!a);

    uint8_t *rawdata = "0x02011A020A0C0AFF4C00100503182EBBBB";
    int8_t *raw_data_1 = strstr(rawdata, "0x");
    printf("%s\n", raw_data_1 + 2);
    int len = strlen(rawdata) * 3;
    uint8_t *newdata = hex_format(rawdata + 2, strlen(rawdata + 2));
    printf("[%s]\n", newdata);
    stringhexarray_to_intarray(newdata[1]);
    free(newdata);
    newdata = NULL;
}

// #include<WinSock.h>//头文件

#if 0 // 学习使用windows 的socket
#pragma comment(lib, "ws2_32.lib")

//#define WIN32_LEAN_AND_MEAN
#include <windows.h>
//#include <winsock2.h> //头文件

//#include<stdlib.h>
//#pragma comment(lib,"ws2_32.lib")
//#include<stdio.h>
#define DEFAULT_PORT 1399
#define BUFFER_LENGTH 1024

#define DATA_BUFFER 1024
void socket_client_create(char *argv[])
{
    printf("input ip:%s\n",argv[1]);
    WSADATA wsaData;
    SOCKET sClient;
    int iPort = DEFAULT_PORT;
    int iLen;
    char buf[DATA_BUFFER];
    struct sockaddr_in ser;

    memset(buf, 0, sizeof(buf));
    if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
    {
        printf("Failed to load Winsock.\n");
        return;
    }
    ser.sin_family = AF_INET;
    ser.sin_port = htons(iPort);
    ser.sin_addr.s_addr = inet_addr(argv[1]);

    sClient = socket(AF_INET, SOCK_STREAM, 0);
    if (sClient == INVALID_SOCKET)
    {
        printf("socket() Failed:%d\n", WSAGetLastError());
        return;
    }
    if (connect(sClient, (struct sockaddr *)&ser, sizeof(ser)) == INVALID_SOCKET)
    {
        printf("connect() Failed:%d\n", WSAGetLastError());
        return;
    }
    else
    {
        iLen = recv(sClient, buf, sizeof(buf), 0);
        if (iLen == 0)
            return;
        else if (iLen == SOCKET_ERROR)
        {
            printf("recv() Failed:%d\n", WSAGetLastError());
            return;
        }
        printf("recv() data from server:%s\n", buf);
    }
    closesocket(sClient);
    WSACleanup();
}
void socket_server_create(char *argv[])
{
    int iPort = DEFAULT_PORT;
    WSADATA wsaData;
    SOCKET sSocket;
    int iLen;
    int iSend;
    int iRecv;
    char send_buf[] = "hello i am a server";
    char recv_buf[BUFFER_LENGTH];
    struct sockaddr_in ser, cli;
    printf("-------\n");
    printf("server waiting\n");
    printf("-------\n");

    if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
    {
        printf("failed to load winsock.\n");
        return;
    }

    sSocket = socket(AF_INET, SOCK_DGRAM, 0);
    if (sSocket == INVALID_SOCKET)
    {
        printf("socket() failed :%d", WSAGetLastError());
        return;
    }
    ser.sin_family = AF_INET;
    ser.sin_port = htons(iPort);
//    ser.sin_addr.s_addr = htonl(INADDR_ANY);
    ser.sin_addr.s_addr = inet_addr("127.0.0.1");
//    htons

    if (bind(sSocket, (LPSOCKADDR)&ser, sizeof(ser)) == SOCKET_ERROR)
    {
        printf("bind() failed :%d", WSAGetLastError());
        return;
    }

    iLen = sizeof(cli);
    memset(recv_buf, 0, sizeof(recv_buf));
    while (1)
    {
        iRecv = recvfrom(sSocket, recv_buf, BUFFER_LENGTH, 0, (SOCKADDR *)&cli, &iLen);
        if (iRecv == SOCKET_ERROR)
        {
            printf("failed ");
            break;
        }
        else if (iRecv == 0)
            break;
        else
        {
            printf(""),
                   inet_ntoa(cli.sin_addr),
                   ntohs(cli.sin_port);
        }
        iSend = sendto(sSocket, send_buf, sizeof(send_buf), 0, (SOCKADDR *)&cli, sizeof(cli));
        if (iSend == SOCKET_ERROR)
        {
            printf("sendto() failed ");
            printf("-----");
            break;
        }
        else if (iSend == 0)
            break;
        else
        {
            printf("send to succed");
            printf("-----");
        }
    }
    closesocket(sSocket);
    WSACleanup();
}
void code_47(char *argv[])
{
    printf("test socket\n");

    socket_server_create(argv);
//        socket_client_create(argv);

}
#endif // 1

void code_48()
{
    char *name[] = {"AAAAAAAA", "AAAAbAAAA", "AAAcAAAA"};
    printf("%d\n", sizeof(name) / sizeof(name[0]));
}

void json_test()
{
    char str[500] = {0};
    sprintf(str, "111");
}

void code_49()
{
    int32_t a = 0xFFFFFFFF;
    printf("[%d]\n", a);

    int item = 100 % 0;
    printf("item [%d]\n", item);
}

char *str1 = "da2AaAA2Asds2A", *str2 = "2A";
char *match_string(char *src, char *str)
{
    if (src == NULL || str == NULL)
    {
        return NULL;
    }

    int str_len = strlen(str), targetstrlen = strlen(src); // 先拿到字符串长度
    printf("target[%d][%s] src[%d][%s]\n", str_len, str, targetstrlen, src);

    char *buf = NULL;
    int count = 0;

    for (int i = 0; i < targetstrlen; i++)
    {
        if (buf == NULL)
        {
            buf = malloc(str_len); // 准备一块大小同目标字符串一样大小的空间
        }

        memset(buf, 0, sizeof(buf)); // 清空

        if (i + str_len > targetstrlen) // 判定边界,如果达到源字符串长度就不必继续了
        {
            if (buf != NULL)
            {
                printf("match count [%d]\n", count); // 输出最终统计结果

                free(buf); // 释放空间
            }
            return "yes";
        }

        memcpy(buf, src + i, str_len); // 源字符串从index地址向下拷贝长度为目标字符串长度的内容到准备好的空间
        if (strcmp(str, buf) == 0)     // 比较
        {
            count++; // 有相同则记为一次成功匹配

            printf("%d %s\n", i, buf); // 打印输出当时匹配到的index值和内容
        }
    }

    return NULL;
}

void code_50()
{
    int i = 0, index = 0, date = 0, data_len = 0, c = 1;
    char buf[10] = {0}, *d = "2022,1,55,4854,85";
    for (i = 0; i <= strlen(d); i++)
    {
        printf("i[%d] index[%d] data_len[%d]\n", i, index, data_len);

        if (d[i] == ',' || d[i] == '\0')
        {
            memset(buf, 0, sizeof(buf));
            memcpy(buf, d + index, data_len);
            date = atoi(buf);

            if (index == 0)
            {
                index = i + 1;
            }
            else
            {
                c++;
                index += index - 1 * c;
            }
            data_len = 1;

            printf("%d\n", date);
            i++;
        }
        else
        {
            data_len++;
        }
    }
}

static void code_51()
{
    // 测试 sscanf
    //    code_50();
    //
    char *data = "2022,11,24,12,17,40";
    int year[8] = {0};
    sscanf(data, "%d,%d,%d,%d,%d,%d", &year[0], &year[1], &year[2], &year[3], &year[4], &year[5]);
    printf("%d,%d,%d,%d,%d,%d", year[0], year[1], year[2], year[3], year[4], year[5]);

    //    int day, year;
    //    char weekday[20], month[20], dtm[100];
    //
    //    strcpy( dtm, "Saturday March 25 1989" );
    //    sscanf( dtm, "%s %s %d  %d", weekday, month, &day, &year );
    //
    //    printf("%s %d, %d = %s\n", month, day, year, weekday );
}
static void menu_create(char *m)
{
    //    printf("%p\n",m);
    ////    printf("--%s\n",&m[0]);
    //    char *menu = m;
    //        printf("%s\n",m[0]);
    //
    //
    //    for (int8_t i = 0; i < 2; i++)
    //    {
    //        sprintf(menu[i], "%s %d", "--<< ", i);
    //        printf("---->%s %s\n",menu[i]);
    //
    //    }

    char menu[2][50] = {0};
    int8_t count = sizeof(menu) / sizeof(menu[0]);
    for (int8_t i = 0; i < count; i++)
    {
        sprintf(menu[i], "%s %d", "---", i);
        printf("%s\n", menu[i]);
    }
}

static void code_52()
{
    char menu[2][50] = {"213", "12"};
    //        printf("%p %s\n",menu,menu[0]);

    menu_create(&menu);
    //    printf(">>>>>%s %s\n",menu[0],menu[1]);
}

void code_53()
{
    char *str = {"111213141516"};
    uint8_t mac[6] = {0};
    sscanf(str, "%02x%02x%02x%02x%02x%02x", &mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]);
    printf("mac [");
    for (int i = 0; i < 6; i++)
    {
        printf("%x ", mac[i]);
    }
    printf("]\n");
}

void code_54()
{
#define X_LEN (5)
#define Y_LEN (5)
#if 0
    int number[X_LEN][Y_LEN] = {0};
    number[0][0] = 1;

#else
    int *number = malloc(sizeof(int) * X_LEN * Y_LEN);
    memset(number, 1, sizeof(int) * X_LEN * Y_LEN);

//    *(*(number+3)+3) = 100;
#endif

    for (int i = 0; i < X_LEN; i++)
    {
        for (int o = 0; o < Y_LEN; o++)
        {
            printf("%d ", *(number + i) + o);
            //            printf("%p ", (int)*(*(number+i)+o));
        }
        printf("\n");
    }

    if (number != NULL)
    {
        free(number);
        number = NULL;
    }
}

void code_55()
{
    int num[5][5] = {{0}, {0}};
    num[1][2] = 2;
    for (int i = 0; i < sizeof(num) / sizeof(num[0]); i++)
    {

        for (int o = 0; o < sizeof(num[0]) / sizeof(num[0][0]); o++)
        {
            printf("%x %d ", &num[i][o], num[i][o]);
        }
        printf("\n");
    }

    printf("---------------------------------------------------\n");

    int *Num = malloc(sizeof(int) * 5 * 5);
    memset(Num, 0, sizeof(int) * 5 * 5);
    memcpy(Num, num, sizeof(int) * 5 * 5);

    int check_num = 0;
    memcpy(&check_num, Num + 1 * 5 + 2, sizeof(int));

    for (int i = 0; i < sizeof(num) / sizeof(num[0]); i++)
    {

        for (int o = 0; o < sizeof(num[0]) / sizeof(num[0][0]); o++)
        {
            printf("%x %d ", &num[i][o], num[i][o]);
        }
        printf("\n");
    }

    printf("%d \n", check_num);

    if (Num != NULL)
    {
        free(Num);
        Num = NULL;
    }

    for (int i = 0; i < sizeof(num) / sizeof(num[0]); i++)
    {

        for (int o = 0; o < sizeof(num[0]) / sizeof(num[0][0]); o++)
        {
            printf("%x %d ", &num[i][o], num[i][o]);
        }
        printf("\n");
    }
}

void code_56()
{
    char *str = "abcdefghijk";
    while (*str)
    {
        printf("%c ", *str);
        str++;
    }

    int a = 1;
    printf("%d \n", a << 127);
}

void code_57()
{
    int a = 1;
    char *str = "abvcd";
    printf("%d \n", str[0] == 'c' ? 12 : 20);

    int8_t index_f = 0, index_l = 0;
    while (index_f < 100 || index_l < 100)
    {
        printf("%d %d \t", index_l++, ++index_f);
    }
}

#if 0
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdlib.h>
#include <stdio.h>

#define NO_ERROR 0L // dderror

// Need to link with Ws2_32.lib
#pragma comment(lib, "Ws2_32.lib")
#pragma comment(lib, "Mswsock.lib")
#pragma comment(lib, "AdvApi32.lib")
int code_58()
{

    //----------------------
    // Initialize Winsock
    WSADATA wsaData;
    int iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
    if (iResult != NO_ERROR)
    {
        wprintf(L"WSAStartup function failed with error: %d\n", iResult);
        return 1;
    }
    //----------------------
    // Create a SOCKET for connecting to server
    SOCKET ConnectSocket;
    ConnectSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    if (ConnectSocket == INVALID_SOCKET)
    {
        wprintf(L"socket function failed with error: %ld\n", WSAGetLastError());
        WSACleanup();
        return 1;
    }
    //----------------------
    // The sockaddr_in structure specifies the address family,
    // IP address, and port of the server to be connected to.
    sockaddr_in clientService;
    clientService.sin_family = AF_INET;
    clientService.sin_addr.s_addr = inet_addr("127.0.0.1");
    clientService.sin_port = htons(27015);

    //----------------------
    // Connect to server.
    iResult = connect(ConnectSocket, (SOCKADDR *)&clientService, sizeof(clientService));
    if (iResult == SOCKET_ERROR)
    {
        wprintf(L"connect function failed with error: %ld\n", WSAGetLastError());
        iResult = closesocket(ConnectSocket);
        if (iResult == SOCKET_ERROR)
            wprintf(L"closesocket function failed with error: %ld\n", WSAGetLastError());
        WSACleanup();
        return 1;
    }

    wprintf(L"Connected to server.\n");

    iResult = closesocket(ConnectSocket);
    if (iResult == SOCKET_ERROR)
    {
        wprintf(L"closesocket function failed with error: %ld\n", WSAGetLastError());
        WSACleanup();
        return 1;
    }

    WSACleanup();
    return 0;
}
#endif

void code_59(int argc, char *argv[])
{
    uint8_t num = 0x01;
    // num |= atoi(argv[1]);
    sscanf(argv[1], "%02x", &num);
    printf("->[%x]\n", num);
}

void code_60(int *num)
{
    *num = 12;
}

// L76K checksum
void code_61()
{
    int check_sum = 0;
    char *content = "GPTXT,01,01,01,ANTENNA OK";
    while (*content)
    {
        check_sum ^= *content;
        content++;
    }
    printf("check_sum[%02x]\n", check_sum);
}
void code_62()
{

    //    code_59(argc, argv);
    //    int mm = 0xd4;
    //    mm |= 0x01;
    //
    //    printf("-->%x\n", mm);
    //
    //    int mm1 = 0;
    //    code_60(&mm1);
    //    printf(">>%d\n", mm1);

    char buf[100] = {""};
    printf("[%d] !!!\n", strlen(buf));

    if (strcmp(buf, "") == 0)
    {
        printf("check !!!\n");
    }

    char *a = {"F1:02:03:04:05:06"};
    uint8_t buf1[6] = {1, 2, 3, 4, 5, 6};
    uint8_t buf2[6] = {0xf1, 2, 3, 4, 5, 6};

    sscanf(a, "%02x:%02x:%02x:%02x:%02x:%02x", &buf1[0], &buf1[1], &buf1[2], &buf1[3], &buf1[4], &buf1[5]);
    printf("write mac[");
    for (int i = 0; i < 6; i++)
    {
        printf("%02x ", buf1[i]);
    }
    printf("]\n");

    printf("write mac[");
    for (int i = 0; i < 6; i++)
    {
        printf("%02x ", buf2[i]);
    }
    printf("]\n");

    if (memcmp(buf1, buf2, 6) == 0)
    {
        printf("like\n");
    }
}

void code_63()
{

    uint8_t buf2[6] = {0};
    int check = buf2[0] + buf2[1] + buf2[2] + buf2[3] + buf2[4] + buf2[5];
    if (check == 0)
    {
        printf("like\n");
    }
    int index = 0;
    for (int i = 0; i < 6; i++)
    {
        check += buf2[i];
        index = i;
    }
    if (check == 0)
    {
        printf("like %d\n", index);
    }

    if (memcmp(buf2, 0, 6) == 0)
    {
        printf("like\n");
    }
}

// 数据解析
void code_64(char *str)
{
    if (str == NULL)
    {
        return;
    }

    char buf[20] = {0};
    int index = 0, len = 0, len_count = 0, dot_count = 0, last_len = 0;
    for (int i = 0; i <= strlen(str); i++)
    {
        // printf("[%c]\t", str[i]);
        if (str[i] == ',' || i == strlen(str))
        {
            if (len > 0)
            {
                memset(buf, 0, sizeof(buf));

                memcpy(buf, str + i - len, len);

                printf("---[%d][%c]\tdata[%s]\n", i - len, *(str + i - len), buf);
            }
            len = 0;
            dot_count++;
        }
        else
        {
            len++;
        }
    }

    printf("dot count[%d]\n", dot_count);
}

#include "stdbool.h"
typedef enum
{
    GPS_SRC_GPS, // GPS
    GPS_SRC_GLONASS,
    GPS_SRC_BD,
    GPS_SRC_QZSS,
    GPS_SRC_OTHER,
} gps_data_src_e; // GPS数据源

typedef struct
{
    uint8_t talker[3];
    uint8_t SentenceFormatter[4];
} gps_address_t;

typedef struct
{
    int utc_year;
    int utc_mon;
    int utc_day;
    int utc_hour;
    int utc_min;
    int utc_sec;
    int utc_msec;
} gps_data_utc_t;

typedef enum
{
    LOCATION_INVALID,
    LOCATION_NORMAL,
} gps_location_state_e;

typedef enum
{
    HEMISPHERE_EAST,  // 东
    HEMISPHERE_SOUTH, // 南
    HEMISPHERE_WEST,  // 西
    HEMISPHERE_NORTH, // 北

} gps_course_e;
typedef enum
{
    MODE_INDICATION_A, // 自主定位
    MODE_INDICATION_D, // 差分
    MODE_INDICATION_E, // 估算
    MODE_INDICATION_N, // 数据无效
} gps_mode_indication_e;
//$GNRMC,090944.000,V,,,,,,,161222,,,N,V*2D
typedef struct
{
    gps_data_utc_t utc;                    // utc时间 yy mm dd hh mm ss.sss
    gps_location_state_e location_state;   // 定位状态
    double latitude;                       // 纬度
    gps_course_e latitude_hemisphere;      // 纬度半球
    double longitude;                      // 经度
    gps_course_e longitude_hemisphere;     // 经度半球
    double ground_speed;                   // 地面速率
    double ground_course;                  // 地面航向
    double declination;                    // 磁偏角
    gps_course_e declination_course;       // 磁偏角方向
    gps_mode_indication_e mode_indication; // 模式指示

} gps_data_rmc_t;

//$GNGGA,090945.004,3205.20197,N,11852.59108,E,1,06,5.1,9.7,M,0.9,M,,*71
typedef struct
{
    gps_data_utc_t utc;                  // utc时间 yy mm dd hh mm ss.sss
    double latitude;                     // 纬度
    gps_course_e latitude_hemisphere;    // 纬度半球
    double longitude;                    // 经度
    gps_course_e longitude_hemisphere;   // 经度半球
    gps_location_state_e location_state; // 定位状态
    int satellites_count;                // 卫星数量
    double precision_level;              // 水平精度
    double sea_level;                    // 天线距海平面高度
    double ground_level;                 // 大地水准面高度
    int differential_data_life;          // 差分 GPS 数据期限
    int differential_data_bsn;           // 差分 GPS 数据基站标号
} gps_data_gga_t;

//$GPGSV,2,1,05,04,49,243,34,08,57,215,36,09,35,291,37,27,,,29,0*5E
#define GSV_NUM_MAX (20)
typedef struct
{
    int message_num;                      // 电文数
    int message_index;                    // 语句号
    int visible_count;                    // 可视卫星总数
    int satellite_index[GSV_NUM_MAX];     // 卫星编号
    int satellite_elevation[GSV_NUM_MAX]; // 卫星仰角
    int satellite_azimuth[GSV_NUM_MAX];   // 卫星方位角
    int satellite_snr[GSV_NUM_MAX];       // 卫星信噪比
    int signalid;                         // 信号标识符

} gps_data_gsv_t;

typedef enum
{
    LOCATION_MODE_AUTO,             // 自动
    LOCATION_MODE_MANUAL_OPERATION, // 手动
} gps_location_mode_e;
typedef enum
{
    LOCATION_TYPE_N,  // 没有定位
    LOCATION_TYPE_2D, // 二维定位
    LOCATION_TYPE_3D, // 三维定位

} gps_location_type_e;
//$GNGSA,A,3,10,36,40,,,,,,,,,,8.0,5.1,6.2,4*3C
typedef struct
{
    gps_location_mode_e mode;         // 定位模式
    gps_location_type_e type;         // 定位形式
    int satellite_index[GSV_NUM_MAX]; // 卫星编号
    double PDOP;                      // 位置精度因子
    double HDOP;                      // 水平精度因子
    double VDOP;                      // 垂直精度因子
    int systemid;                     // 系统标识符

} gps_data_gsa_t;

//$GNVTG,,,,,,,,,N*2E
typedef struct
{
    int ground_course_true;                // 以真北为参考基准的地面航向
    int ground_course_magnetic;            // 以磁北为参考基准的地面航向
    double ground_speed_knot;              // 地面速率(节)
    double ground_speed_km;                // 地面速率(km/h)
    gps_mode_indication_e mode_indication; // 模式指示

} gps_data_vtg_t;

typedef struct
{
    double latitude;                       // 纬度
    gps_course_e latitude_hemisphere;      // 纬度半球
    double longitude;                      // 经度
    gps_course_e longitude_hemisphere;     // 经度半球
    gps_data_utc_t utc;                    // utc时间 yy mm dd hh mm ss.sss
    gps_location_state_e location_state;   // 定位状态
    gps_mode_indication_e mode_indication; // 模式指示

} gps_data_gll_t;

typedef struct
{
    gps_data_utc_t utc; // utc时间 yy mm dd hh mm ss.sss
    int day;            // 日
    int mon;            // 月
    int year;           // 年
    int localhour;      // 暂不支持
    int localmin;       // 暂不支持

} gps_data_zda_t;

typedef struct
{
    int total;     // 语句总数
    int index;     // 语句编号
    int flag;      // 文本标识符
    char txt[120]; // 文本信息

} gps_data_txt_t;

typedef struct
{
    gps_data_rmc_t rmc;
    gps_data_gga_t gga;
    gps_data_gsv_t gsv;
    gps_data_gsa_t gsa;
    gps_data_vtg_t vtg;
    gps_data_gll_t gll;
    gps_data_zda_t zda;
    gps_data_txt_t txt;

} gps_data_t;

typedef struct
{
    gps_address_t address;
    gps_data_t data;
    uint8_t checksum;

} gps_t;
static gps_t gps = {0};
static int gps_get_dot_count(char *str)
{
    if (str == NULL)
    {
        return 0;
    }

    int dot_count = 0;
    while (*str)
    {
        if (*str == ',')
        {
            dot_count++;
        }
        str++;
    }
    printf("dot count [%d]\n", dot_count);
    return dot_count;
}

static void gps_parse_rmc(char *str)
{
    if (str == NULL)
    {
        return;
    }

    char buf[20] = {0};
    int index = 0, len = 0, len_count = 0, dot_count = 0, last_len = 0;
    for (int i = 0; i <= strlen(str); i++)
    {
        // printf("[%c]\t", str[i]);
        if (str[i] == ',' || str[i] == '*' || i == strlen(str))
        {
            if (len > 0)
            {
                memset(buf, 0, sizeof(buf));

                memcpy(buf, str + i - len, len);

                printf("[%s] ", buf);

                switch (dot_count)
                {
                case 1: // 获取UTC时间
                {
                    sscanf(buf, "%02d%02d%02d.%03d",
                           &gps.data.rmc.utc.utc_hour,
                           &gps.data.rmc.utc.utc_min,
                           &gps.data.rmc.utc.utc_sec,
                           &gps.data.rmc.utc.utc_msec);
                }
                break;
                case 2: // 获取定位状态
                {
                    if (strcmp(buf, "A") == 0)
                    {
                        gps.data.rmc.location_state = LOCATION_NORMAL;
                    }
                    else if (strcmp(buf, "V") == 0)
                    {
                        gps.data.rmc.location_state = LOCATION_INVALID;
                    }
                }
                break;
                case 3: // 获取纬度
                {
                    sscanf(buf, "%lf", &gps.data.rmc.latitude);
                }
                break;
                case 4: // 获取纬度半球
                {
                    if (strcmp(buf, "N") == 0)
                    {
                        gps.data.rmc.latitude_hemisphere = HEMISPHERE_NORTH;
                    }
                    else if (strcmp(buf, "S") == 0)
                    {
                        gps.data.rmc.latitude_hemisphere = HEMISPHERE_SOUTH;
                    }
                }
                break;
                case 5: // 获取经度
                {
                    sscanf(buf, "%lf", &gps.data.rmc.longitude);
                }
                break;
                case 6: // 获取经度半球
                {
                    if (strcmp(buf, "E") == 0)
                    {
                        gps.data.rmc.longitude_hemisphere = HEMISPHERE_EAST;
                    }
                    else if (strcmp(buf, "W") == 0)
                    {
                        gps.data.rmc.longitude_hemisphere = HEMISPHERE_WEST;
                    }
                }
                break;
                case 7: // 获取地面速率
                {
                    sscanf(buf, "%lf", &gps.data.rmc.ground_speed);
                }
                break;
                case 8: // 获取地面航向
                {
                    sscanf(buf, "%lf", &gps.data.rmc.ground_course);
                }
                break;
                case 9: // 获取UTC日期
                {
                    sscanf(buf, "%02d%02d%02d",
                           &gps.data.rmc.utc.utc_day,
                           &gps.data.rmc.utc.utc_mon,
                           &gps.data.rmc.utc.utc_year);
                }
                break;
                case 10: // 获取磁偏角
                {
                    sscanf(buf, "%lf", &gps.data.rmc.declination);
                }
                break;
                case 11: // 获取磁偏角方向
                {
                    if (strcmp(buf, "E") == 0)
                    {
                        gps.data.rmc.declination_course = HEMISPHERE_EAST;
                    }
                    else if (strcmp(buf, "W") == 0)
                    {
                        gps.data.rmc.declination_course = HEMISPHERE_WEST;
                    }
                }
                break;
                case 12: // 获取模式指示
                {
                    if (strcmp(buf, "A") == 0)
                    {
                        gps.data.rmc.mode_indication = MODE_INDICATION_A;
                    }
                    else if (strcmp(buf, "D") == 0)
                    {
                        gps.data.rmc.mode_indication = MODE_INDICATION_D;
                    }
                    else if (strcmp(buf, "E") == 0)
                    {
                        gps.data.rmc.mode_indication = MODE_INDICATION_E;
                    }
                    else if (strcmp(buf, "N") == 0)
                    {
                        gps.data.rmc.mode_indication = MODE_INDICATION_N;
                    }
                }
                break;

                default:
                    break;
                }
            }
            len = 0;
            dot_count++;
        }
        else
        {
            len++;
        }
    }

    printf("dot count[%d]\n", dot_count);
}
static void gps_parse_gga(char *str)
{
    if (str == NULL)
    {
        return;
    }

    char buf[20] = {0};
    int index = 0, len = 0, len_count = 0, dot_count = 0, last_len = 0;
    for (int i = 0; i <= strlen(str); i++)
    {
        // printf("[%c]\t", str[i]);
        if (str[i] == ',' || str[i] == '*' || i == strlen(str))
        {
            if (len > 0)
            {
                memset(buf, 0, sizeof(buf));

                memcpy(buf, str + i - len, len);

                printf("[%s] ", buf);

                switch (dot_count)
                {
                case 1: // 获取UTC时间
                {
                    sscanf(buf, "%02d%02d%02d.%03d",
                           &gps.data.gga.utc.utc_hour,
                           &gps.data.gga.utc.utc_min,
                           &gps.data.gga.utc.utc_sec,
                           &gps.data.gga.utc.utc_msec);
                }
                break;
                case 2: // 获取纬度
                {
                    sscanf(buf, "%lf", &gps.data.gga.latitude);
                }
                break;
                case 3: // 获取纬度半球
                {
                    if (strcmp(buf, "N") == 0)
                    {
                        gps.data.gga.latitude_hemisphere = HEMISPHERE_NORTH;
                    }
                    else if (strcmp(buf, "S") == 0)
                    {
                        gps.data.gga.latitude_hemisphere = HEMISPHERE_SOUTH;
                    }
                }
                break;
                case 4: // 获取经度
                {
                    sscanf(buf, "%lf", &gps.data.gga.longitude);
                }
                break;
                case 5: // 获取经度半球
                {
                    if (strcmp(buf, "E") == 0)
                    {
                        gps.data.gga.longitude_hemisphere = HEMISPHERE_EAST;
                    }
                    else if (strcmp(buf, "W") == 0)
                    {
                        gps.data.gga.longitude_hemisphere = HEMISPHERE_WEST;
                    }
                }
                break;
                case 6: // 获取定位质量指示
                {
                    if (strcmp(buf, "0") == 0)
                    {
                        gps.data.gga.location_state = LOCATION_INVALID;
                    }
                    else
                    {
                        gps.data.gga.location_state = LOCATION_NORMAL;
                    }
                }
                break;
                case 7: // 获取使用卫星数量
                {
                    sscanf(buf, "%d", &gps.data.gga.satellites_count);
                }
                break;
                case 8:
                {
                    sscanf(buf, "%lf", &gps.data.gga.precision_level);
                }
                break;
                case 9:
                {
                    sscanf(buf, "%lf", &gps.data.gga.sea_level);
                }
                break;
                case 11:
                {
                    sscanf(buf, "%lf", &gps.data.gga.ground_level);
                }
                break;
                case 13:
                {
                    sscanf(buf, "%d", &gps.data.gga.differential_data_life);
                }
                break;
                case 14:
                {
                    sscanf(buf, "%d", &gps.data.gga.differential_data_bsn);
                }
                break;
                default:
                    break;
                }
            }
            len = 0;
            dot_count++;
        }
        else
        {
            len++;
        }
    }

    printf("dot count[%d]\n", dot_count);
}
static void gps_parse_gsv(char *str)
{
    if (str == NULL)
    {
        return;
    }

    int dot_c = gps_get_dot_count(str);

    char buf[20] = {0};
    int index = 0, len = 0, len_count = 0, dot_count = 0, index_2 = 0;
    for (int i = 0; i <= strlen(str); i++)
    {
        // printf("[%c]\t", str[i]);
        if (str[i] == ',' || str[i] == '*' || i == strlen(str))
        {
            if (len > 0)
            {
                memset(buf, 0, sizeof(buf));

                memcpy(buf, str + i - len, len);
                printf("[%s] ", buf);

                switch (dot_count)
                {
                case 1: // 获取电文数
                {
                    sscanf(buf, "%02d", &gps.data.gsv.message_num);
                }
                break;
                case 2: // 获取语句号
                {
                    sscanf(buf, "%02d", &gps.data.gsv.message_index);
                }
                break;
                case 3: // 获取可视卫星总数
                {
                    sscanf(buf, "%02d", &gps.data.gsv.visible_count);
                }
                break;
                default: // 卫星参数
                {
                    if (dot_count == dot_c)
                    {
                        sscanf(buf, "%d", &gps.data.gsv.signalid);
                        break;
                    }

                    index = (dot_count - 4) % 4;
                    index_2 = (dot_count - 4) / 4;
                    switch (index)
                    {
                    case 0: // 卫星号
                    {
                        sscanf(buf, "%d", &gps.data.gsv.satellite_index[index_2]);
                    }
                    break;
                    case 1: // 仰角
                    {
                        sscanf(buf, "%d", &gps.data.gsv.satellite_elevation[index_2]);
                    }
                    break;
                    case 2: // 方位角
                    {
                        sscanf(buf, "%d", &gps.data.gsv.satellite_azimuth[index_2]);
                    }
                    break;
                    case 3: // 信噪比
                    {
                        sscanf(buf, "%d", &gps.data.gsv.satellite_snr[index_2]);
                    }
                    break;
                    default:
                        break;
                    }
                }
                break;
                }
            }
            len = 0;
            dot_count++;
        }
        else
        {
            len++;
        }
    }

    printf("dot count[%d]\n", dot_count);
}
static void gps_parse_gsa(char *str)
{
    if (str == NULL)
    {
        return;
    }

    char buf[20] = {0};
    int index = 0, len = 0, len_count = 0, dot_count = 0, sate_index = 0;
    int dot_c = gps_get_dot_count(str);

    for (int i = 0; i <= strlen(str); i++)
    {
        // printf("[%c]\t", str[i]);
        if (str[i] == ',' || str[i] == '*' || i == strlen(str))
        {
            if (len > 0)
            {
                memset(buf, 0, sizeof(buf));

                memcpy(buf, str + i - len, len);

                printf("[%s] ", buf);

                switch (dot_count)
                {
                case 1: // 获取模式
                {
                    if (strcmp(buf, "M") == 0)
                    {
                        gps.data.gsa.mode = LOCATION_MODE_MANUAL_OPERATION;
                    }
                    else if (strcmp(buf, "A") == 0)
                    {
                        gps.data.gsa.mode = LOCATION_MODE_AUTO;
                    }
                }
                break;
                case 2: // 获取定位形式
                {
                    if (strcmp(buf, "1") == 0)
                    {
                        gps.data.gsa.type = LOCATION_TYPE_N;
                    }
                    else if (strcmp(buf, "2") == 0)
                    {
                        gps.data.gsa.type = LOCATION_TYPE_2D;
                    }
                    else if (strcmp(buf, "3") == 0)
                    {
                        gps.data.gsa.type = LOCATION_TYPE_3D;
                    }
                }
                break;

                default:
                    if (dot_count > dot_c - 1 - 3) // 获取精度因子
                    {
                        switch (dot_c - dot_count)
                        {
                        case 3:
                        {
                            sscanf(buf, "%lf", &gps.data.gsa.PDOP);
                        }
                        break;
                        case 2:
                        {
                            sscanf(buf, "%lf", &gps.data.gsa.HDOP);
                        }
                        break;
                        case 1:
                        {
                            sscanf(buf, "%lf", &gps.data.gsa.VDOP);
                        }
                        break;
                        case 0:
                        {
                            sscanf(buf, "%d", &gps.data.gsa.systemid);
                        }
                        break;

                        default:
                            break;
                        }
                    }
                    else // 获取卫星编号
                    {
                        sscanf(buf, "%02d", &gps.data.gsa.satellite_index[sate_index++]);
                    }
                    break;
                }
            }
            len = 0;
            dot_count++;
        }
        else
        {
            len++;
        }
    }

    printf("dot count[%d]\n", dot_count);
}
static void gps_parse_vtg(char *str)
{
    if (str == NULL)
    {
        return;
    }

    char buf[20] = {0};
    int index = 0, len = 0, len_count = 0, dot_count = 0, last_len = 0;
    for (int i = 0; i <= strlen(str); i++)
    {
        // printf("[%c]\t", str[i]);
        if (str[i] == ',' || str[i] == '*' || i == strlen(str))
        {
            if (len > 0)
            {
                memset(buf, 0, sizeof(buf));

                memcpy(buf, str + i - len, len);

                printf("[%s] ", buf);

                switch (dot_count)
                {
                case 1: // 获取真北地面航向角度
                {
                    sscanf(buf, "%03d", &gps.data.vtg.ground_course_true);
                }
                break;
                case 2: // 获取磁北地面航向角度
                {
                    sscanf(buf, "%03d", &gps.data.vtg.ground_course_magnetic);
                }
                break;
                case 3: // 获取地面速度,单位节
                {
                    sscanf(buf, "%lf", &gps.data.vtg.ground_speed_knot);
                }
                break;
                case 4: // 获取地面速度,单位km/h
                {
                    sscanf(buf, "%lf", &gps.data.vtg.ground_speed_knot);
                }
                break;
                case 5: // 获取模式指示
                {
                    if (strcmp(buf, "A") == 0)
                    {
                        gps.data.vtg.mode_indication = MODE_INDICATION_A;
                    }
                    else if (strcmp(buf, "D") == 0)
                    {
                        gps.data.vtg.mode_indication = MODE_INDICATION_D;
                    }
                    else if (strcmp(buf, "E") == 0)
                    {
                        gps.data.vtg.mode_indication = MODE_INDICATION_E;
                    }
                    else if (strcmp(buf, "N") == 0)
                    {
                        gps.data.vtg.mode_indication = MODE_INDICATION_N;
                    }
                }
                break;

                default:
                    break;
                }
            }
            len = 0;
            dot_count++;
        }
        else
        {
            len++;
        }
    }

    printf("dot count[%d]\n", dot_count);
}
static void gps_parse_txt(char *str)
{
    if (str == NULL)
    {
        return;
    }

    char buf[20] = {0};
    int index = 0, len = 0, len_count = 0, dot_count = 0, last_len = 0;
    for (int i = 0; i <= strlen(str); i++)
    {
        // printf("[%c]\t", str[i]);
        if (str[i] == ',' || str[i] == '*' || i == strlen(str))
        {
            if (len > 0)
            {
                memset(buf, 0, sizeof(buf));

                memcpy(buf, str + i - len, len);

                printf("[%s] ", buf);

                switch (dot_count)
                {
                case 1: // 获取语句总数
                {
                    sscanf(buf, "%02d", &gps.data.txt.total);
                }
                break;
                case 2: // 获取语句编号
                {
                    sscanf(buf, "%02d", &gps.data.txt.index);
                }
                break;
                case 3: // 文本标识符
                {
                    sscanf(buf, "%02d", &gps.data.txt.flag);
                }
                break;
                case 4: // 文本内容
                {
                    strncpy(gps.data.txt.txt, buf, strlen(buf));
                }
                break;

                default:
                    break;
                }
            }
            len = 0;
            dot_count++;
        }
        else
        {
            len++;
        }
    }

    printf("dot count[%d]\n", dot_count);
}
static void gps_parse_zda(char *str)
{
    if (str == NULL)
    {
        return;
    }

    char buf[20] = {0};
    int index = 0, len = 0, len_count = 0, dot_count = 0, last_len = 0;
    for (int i = 0; i <= strlen(str); i++)
    {
        // printf("[%c]\t", str[i]);
        if (str[i] == ',' || str[i] == '*' || i == strlen(str))
        {
            if (len > 0)
            {
                memset(buf, 0, sizeof(buf));

                memcpy(buf, str + i - len, len);

                printf("[%s] ", buf);

                switch (dot_count)
                {
                case 1: // 获取UTC时间
                {
                    sscanf(buf, "%02d%02d%02d.%03d",
                           &gps.data.zda.utc.utc_hour,
                           &gps.data.zda.utc.utc_min,
                           &gps.data.zda.utc.utc_sec,
                           &gps.data.zda.utc.utc_msec);
                }
                break;
                case 2: // 获取天
                {
                    sscanf(buf, "%02d", &gps.data.zda.day);
                }
                break;
                case 3: // 获取月
                {
                    sscanf(buf, "%02d", &gps.data.zda.mon);
                }
                break;
                case 4: // 获取年
                {
                    sscanf(buf, "%04d", &gps.data.zda.year);
                }
                break;
                case 5: // 暂不支持
                {
                    sscanf(buf, "%02d", &gps.data.zda.localhour);
                }
                break;
                case 6: // 暂不支持
                {
                    sscanf(buf, "%02d", &gps.data.zda.localmin);
                }
                break;

                default:
                    break;
                }
            }
            len = 0;
            dot_count++;
        }
        else
        {
            len++;
        }
    }

    printf("dot count[%d]\n", dot_count);
}
static void gps_parse_gll(char *str)
{
    if (str == NULL)
    {
        return;
    }

    char buf[20] = {0};
    int index = 0, len = 0, len_count = 0, dot_count = 0, last_len = 0;
    for (int i = 0; i <= strlen(str); i++)
    {
        // printf("[%c]\t", str[i]);
        if (str[i] == ',' || str[i] == '*' || i == strlen(str))
        {
            if (len > 0)
            {
                memset(buf, 0, sizeof(buf));

                memcpy(buf, str + i - len, len);

                printf("[%s] ", buf);

                switch (dot_count)
                {
                case 1: // 获取纬度
                {
                    sscanf(buf, "%lf", &gps.data.gll.latitude);
                }
                break;
                case 2: // 获取纬度方向
                {
                    if (strcmp(buf, "N") == 0)
                    {
                        gps.data.gll.latitude_hemisphere = HEMISPHERE_NORTH;
                    }
                    else if (strcmp(buf, "S") == 0)
                    {
                        gps.data.gll.latitude_hemisphere = HEMISPHERE_SOUTH;
                    }
                }
                break;
                case 3: // 获取经度
                {
                    sscanf(buf, "%lf", &gps.data.gll.longitude);
                }
                break;
                case 4: // 获取经度方向
                {
                    if (strcmp(buf, "E") == 0)
                    {
                        gps.data.gll.longitude_hemisphere = HEMISPHERE_EAST;
                    }
                    else if (strcmp(buf, "W") == 0)
                    {
                        gps.data.gll.longitude_hemisphere = HEMISPHERE_WEST;
                    }
                }
                break;
                case 5: // 获取UTC时间
                {
                    sscanf(buf, "%02d%02d%02d.%03d",
                           &gps.data.gll.utc.utc_hour,
                           &gps.data.gll.utc.utc_min,
                           &gps.data.gll.utc.utc_sec,
                           &gps.data.gll.utc.utc_msec);
                }
                break;
                case 6: // 获取定位系统状态
                {
                    if (strcmp(buf, "A") == 0)
                    {
                        gps.data.gll.location_state = LOCATION_NORMAL;
                    }
                    else if (strcmp(buf, "V") == 0)
                    {
                        gps.data.gll.location_state = LOCATION_INVALID;
                    }
                }
                break;
                case 7: // 获取定位指示
                {
                    if (strcmp(buf, "A") == 0)
                    {
                        gps.data.gll.mode_indication = MODE_INDICATION_A;
                    }
                    else if (strcmp(buf, "D") == 0)
                    {
                        gps.data.gll.mode_indication = MODE_INDICATION_D;
                    }
                    else if (strcmp(buf, "E") == 0)
                    {
                        gps.data.gll.mode_indication = MODE_INDICATION_E;
                    }
                    else if (strcmp(buf, "N") == 0)
                    {
                        gps.data.gll.mode_indication = MODE_INDICATION_N;
                    }
                }
                break;
                default:
                    break;
                }
            }
            len = 0;
            dot_count++;
        }
        else
        {
            len++;
        }
    }

    printf("dot count[%d]\n", dot_count);
}

uint8_t gps_checksum(char *str)
{
    uint8_t checksum = 0, *checksum_str;
    checksum_str = str;
    while (*checksum_str)
    {
        if (*checksum_str == '$')
        {
            checksum_str++;
            continue;
        }
        else if (*checksum_str == '*')
        {
            break;
        }
        checksum ^= *checksum_str;
        checksum_str++;
    }
    // printf("%02x\n", checksum);

    return checksum;
}

void dq_parse_gps(char *str)
{
    // uint8_t *gps_str = {"$GNZDA,090944.000,16,12,2022,00,00*4E"};
    // uint8_t *gps_str = {"$GPTXT,01,01,01,ANTENNA OK*35"};
    // uint8_t *gps_str = {"$GNGGA,090945.004,3205.20197,N,11852.59108,E,1,06,5.1,9.7,M,0.9,M,,*71"};
    // uint8_t *gps_str = {"$GNGLL,3205.20197,N,11852.59108,E,090945.004,A,A*41"};
    // uint8_t *gps_str = {"$GNGSA,A,3,10,36,40,,,,,,,,,,8.0,5.1,6.2,4*3C"};
    // uint8_t *gps_str = {"$GNRMC,090944.000,V,,,,,,,161222,,,N,V*2D"};
    // uint8_t *gps_str = {"$GPGSV,2,1,05,04,49,243,34,08,57,215,36,09,35,291,37,27,,,29,0*5E"};
    // uint8_t *gps_str = {"$GNVTG,,,,,,,,,N*2E"};
    uint8_t *gps_str = str;
    printf("\n\n****************\n%s\n", gps_str);

    memcpy(gps.address.talker, gps_str + 1, 2);
    memcpy(gps.address.SentenceFormatter, gps_str + 3, 3);

    uint8_t buf[3] = {0};
    memcpy(buf, gps_str + strlen(gps_str) - 2, 2);
    sscanf(buf, "%02x", &gps.checksum);

    printf("[%s %s %02x]\n",
           gps.address.talker,
           gps.address.SentenceFormatter,
           gps.checksum);

    // 校验数据完整性
    if (gps.checksum != gps_checksum(gps_str))
    {
        printf("data checksum fail!!! \n%02x vs %02x\n", gps.checksum, gps_checksum(gps_str));
        return;
    }

    // if (strcmp(gps.address.talker, "GP") == 0) // GPS
    // {
    //     printf("GPS\t");
    // }
    // else if (strcmp(gps.address.talker, "GL") == 0) // GLONASS
    // {
    //     printf("GLONASS\t");
    // }
    // else if (strcmp(gps.address.talker, "BD") == 0) // 北斗
    // {
    //     printf("BD\t");
    // }
    // else if (strcmp(gps.address.talker, "GP") == 0) // QZSS
    // {
    //     printf("QZSS\t");
    // }
    // else if (strcmp(gps.address.talker, "GN") == 0) // 组合星系
    // {
    //     printf("GN\t");
    // }

    // 解析数据
    if (strcmp(gps.address.SentenceFormatter, "RMC") == 0) // RMC 推荐定位信息
    {
        gps_parse_rmc(gps_str);

        printf("%d %d %d %d %d %d %d \n%d \n%f %d %f %d \n%f %f %f \n%d %d\n",
               gps.data.rmc.utc.utc_year,
               gps.data.rmc.utc.utc_mon,
               gps.data.rmc.utc.utc_day,
               gps.data.rmc.utc.utc_hour,
               gps.data.rmc.utc.utc_min,
               gps.data.rmc.utc.utc_sec,
               gps.data.rmc.utc.utc_msec,
               gps.data.rmc.location_state,
               gps.data.rmc.latitude,
               gps.data.rmc.latitude_hemisphere,
               gps.data.rmc.longitude,
               gps.data.rmc.longitude_hemisphere,
               gps.data.rmc.ground_speed,
               gps.data.rmc.ground_course,
               gps.data.rmc.declination,
               gps.data.rmc.declination_course,
               gps.data.rmc.mode_indication);
    }
    else if (strcmp(gps.address.SentenceFormatter, "GGA") == 0) // GGA 固定数据输出
    {
        gps_parse_gga(gps_str);

        printf("%d %d %d %d %d %d %d \n%f %d %f %d \n%d %d \n%f %f %f \n%d %d\n",
               gps.data.gga.utc.utc_year,
               gps.data.gga.utc.utc_mon,
               gps.data.gga.utc.utc_day,
               gps.data.gga.utc.utc_hour,
               gps.data.gga.utc.utc_min,
               gps.data.gga.utc.utc_sec,
               gps.data.gga.utc.utc_msec,
               gps.data.gga.latitude,
               gps.data.gga.latitude_hemisphere,
               gps.data.gga.longitude,
               gps.data.gga.longitude_hemisphere,
               gps.data.gga.location_state,
               gps.data.gga.satellites_count,
               gps.data.gga.precision_level,
               gps.data.gga.sea_level,
               gps.data.gga.ground_level,
               gps.data.gga.differential_data_life,
               gps.data.gga.differential_data_bsn);
    }
    else if (strcmp(gps.address.SentenceFormatter, "GSV") == 0) // GSV 可视卫星状态输出语句
    {
        gps_parse_gsv(gps_str);

        printf("%d %d %d %d\n",
               gps.data.gsv.message_num,
               gps.data.gsv.message_index,
               gps.data.gsv.visible_count,
               gps.data.gsv.signalid);

        for (int i = 0; i < GSV_NUM_MAX; i++)
        {
            if (gps.data.gsv.satellite_index[i] != 0)
            {
                printf("%d %d %d %d\n",
                       gps.data.gsv.satellite_index[i],
                       gps.data.gsv.satellite_elevation[i],
                       gps.data.gsv.satellite_azimuth[i],
                       gps.data.gsv.satellite_snr[i]);
            }
        }
    }
    else if (strcmp(gps.address.SentenceFormatter, "GSA") == 0) // GSA 当前卫星信息
    {
        gps_parse_gsa(gps_str);

        printf("%d %d %d \n%f %f %f %d\n",
               gps.data.gsa.mode,
               gps.data.gsa.type,
               gps.data.gsa.satellite_index[0],
               gps.data.gsa.PDOP,
               gps.data.gsa.HDOP,
               gps.data.gsa.VDOP,
               gps.data.gsa.systemid);

        for (int i = 0; i < GSV_NUM_MAX; i++)
        {
            if (gps.data.gsa.satellite_index[i] != 0)
            {
                printf("%d ", gps.data.gsa.satellite_index[i]);
            }
        }
    }
    else if (strcmp(gps.address.SentenceFormatter, "VTG") == 0) // 地面速度
    {
        gps_parse_vtg(gps_str);

        printf("%d %d %d %d %d\n",
               gps.data.vtg.ground_course_true,
               gps.data.vtg.ground_course_magnetic,
               gps.data.vtg.ground_speed_knot,
               gps.data.vtg.ground_speed_km,
               gps.data.vtg.mode_indication);
    }
    else if (strcmp(gps.address.SentenceFormatter, "ZDA") == 0) // 输出 UTC 时间，日、月、年及本地时区
    {
        gps_parse_zda(gps_str);
        printf("%d %d %d %d %d %d %d \n%d %d %d\n",
               gps.data.zda.utc.utc_year,
               gps.data.zda.utc.utc_mon,
               gps.data.zda.utc.utc_day,
               gps.data.zda.utc.utc_hour,
               gps.data.zda.utc.utc_min,
               gps.data.zda.utc.utc_sec,
               gps.data.zda.utc.utc_msec,
               gps.data.zda.day,
               gps.data.zda.mon,
               gps.data.zda.year,
               gps.data.zda.localhour,
               gps.data.zda.localmin);
    }
    else if (strcmp(gps.address.SentenceFormatter, "TXT") == 0) // 文本消息
    {
        gps_parse_txt(gps_str);

        printf("%d %d %d %s\n",
               gps.data.txt.total,
               gps.data.txt.index,
               gps.data.txt.flag,
               gps.data.txt.txt);
    }
    else if (strcmp(gps.address.SentenceFormatter, "GLL") == 0) // 地理位置
    {
        gps_parse_gll(gps_str);

        printf("%f %d %f %d \n%d %d %d %d %d %d %d \n%d %d\n",
               gps.data.gll.latitude,
               gps.data.gll.latitude_hemisphere,
               gps.data.gll.longitude,
               gps.data.gll.longitude_hemisphere,
               gps.data.gll.utc.utc_year,
               gps.data.gll.utc.utc_mon,
               gps.data.gll.utc.utc_day,
               gps.data.gll.utc.utc_hour,
               gps.data.gll.utc.utc_min,
               gps.data.gll.utc.utc_sec,
               gps.data.gll.utc.utc_msec,
               gps.data.gll.location_state,
               gps.data.gll.mode_indication);
    }
}

void check_sum(int argc, char *argv[])
{
    printf("ex:check sum[hex value]\n");
    int check_sum = 0;
    char *content = argv[1];
    while (*content)
    {
        check_sum ^= *content;
        content++;
    }
    printf("check_sum[%02X]\n", check_sum);
}

void gps_raw_data_parse()
{
    uint8_t *raw_str = {"$GNGLL,,,,,,V,N*7A $GNGSA,A,1,,,,,,,,,,,,,25.5,25.5,25.5,1*01 $GNGSA,A,1,,,,,,,,,,,,,25.5,25.5,25.5,4*04 $GPGSV,1,1,00,0*65 $BDGSV,1,1,00,0*74 "};
    printf("%s\n", raw_str);

    uint8_t buf[300] = {0};
    int len = 0, index = 0, dot_count = 0;

    for (int i = 0; i < strlen(raw_str); i++)
    {
        if (raw_str[i] == '$')
        {
            printf("index %d len %d\t ", index, len);
            memset(buf, 0, sizeof(buf));
            memcpy(buf, raw_str + i - len - 1, len);

            dot_count++;
            index += len;
            len = 0;

            // printf("[%s]\n", buf);
            dq_parse_gps(buf);
        }
        else
        {
            len++;
        }
    }
}

int fs_test(int argc, char *argv[])
{
    char *file_path = argv[1];
    if (strcmp(file_path, "-h") == 0)
    {
        printf("ex: getfilesize xxxx\n");
        return 0;
    }
    char *file_open_type = {"r+"};
    FILE *f = fopen(file_path, file_open_type);

    // while (1)
    // {
    //     char c = fgetc(f);
    //     if (c == EOF)
    //     {
    //         break;
    //     }
    //     printf("%c", c);
    // }

    // for (int i = 0; i < 5; i++)
    // {
    //     char buf[200] = {0};
    //     fgets(buf, sizeof(buf), f);
    //     printf("%s", buf);
    // }

    // fpos_t fpos = 100;
    // fsetpos(f, &fpos);

    // for (int i = 0; i < 10; i++)
    // {
    //     fputc(i, f);
    // }

    int file_size = 0;
    fseek(f, 0, SEEK_END);
    file_size = ftell(f);

    // fseek(f, 0, SEEK_SET);
    // for (int i = 0; i <= file_size; i++)
    // {
    //     fputc('c', f);
    // }

    printf("file size[%d]\n", file_size);

    printf("close file\n");
    fclose(f);
}
void code_65()
{
    // check_sum(argc, argv);
    // dq_parse_gps();
    // gps_raw_data_parse();

    // char *str = {"36565.655796"};
    // double num = 0;
    // sscanf(str, "%lf ", &num);
    // printf("%f\n", num);

    // fs_test(argc, argv);
}
void arr_test()
{
    uint8_t pix[10][10] = {0};

    pix[1][9] = 10;
    for (int i = 0; i < 10; i++)
    {
        for (int j = 0; j < 10; j++)
        {
            printf("%d ", pix[i][j]);
        }
        printf("\n");
    }
    printf("\n");

    uint8_t *pix_mem = malloc(100);
    if (pix_mem != NULL)
    {
        memset(pix_mem, 0, 100);

        printf("%d %d\n", sizeof(pix), sizeof(pix_mem));

        pix_mem[19] = 10;

        for (int i = 0; i < 10; i++)
        {
            for (int j = 0; j < 10; j++)
            {
                printf("%d ", pix_mem[i * 10 + j]);
            }
            printf("\n");
        }
        free(pix_mem);
        pix_mem = NULL;
    }
}

void code_66()
{
    int flag = 0;
    flag |= 0x04;
    flag |= 0x10;
    printf("%02x\n", flag);

    flag &= ~0x10;
    printf("%02x\n", flag);

    flag |= 0x11;
    printf("%02x\n", flag);

    printf("%d\n", 0xF000);

    printf("hhhhhhh %02x\n", flag & 0x05);

    printf("%02x\n", flag);

    if (flag && 0x05 == 1)
    {
        printf("hhhhhhh %d\n", flag & 0x14);
    }
}
void code_67()
{
    uint8_t a[] = {0x01, 0x01, 0x02};
    uint8_t b[] = {0x01, 0x01, 0x02};

    memcmp(a, b, sizeof(a)) == 0 ? printf("HHH") : printf("JHJ");
}

int count_num_size(int data)
{
    return ((sizeof(data) + sizeof(int) - 1) & ~(sizeof(int) - 1));
}

// 测试共用体了解它的使用
typedef union
{
    uint32_t num;
    struct
    {
        uint32_t bit_0 : 1;
        uint32_t bit_1 : 1;
        uint32_t bit_2 : 1;
        uint32_t bit_3 : 1;
        uint32_t bit_4 : 1;
        uint32_t bit_5 : 1;
        uint32_t bit_6 : 1;
        uint32_t bit_7 : 1;
        uint32_t bit_8 : 24;
    } bits;
} my_uinon_t;
void code_68()
{
    my_uinon_t test_union;
    test_union.num = 100;
    printf("%d %02x \n", test_union.num, test_union.num);
    printf("%024x ", test_union.bits.bit_8);
    printf("%0x ", test_union.bits.bit_7);
    printf("%0x ", test_union.bits.bit_6);
    printf("%0x ", test_union.bits.bit_5);
    printf("%0x ", test_union.bits.bit_4);
    printf("%0x ", test_union.bits.bit_3);
    printf("%0x ", test_union.bits.bit_2);
    printf("%0x ", test_union.bits.bit_1);
    printf("%0x \n", test_union.bits.bit_0);

    // 最后的结果是这样的,说明 num 和结构体共用一段内存存储数据,
    // 共用体变量中起作用的成员是最后一次被赋值的成员，在对共同体变量中的一个成员赋值后，原有变量存储单元中的值就被取代
    //  100 64
    //  000000000000000000000000 0 1 1 0 0 1 0 0
}

// 测试实现构建复杂指令结构体和使用
uint8_t code_70(int argc, char *argv[])
{
    for (int i = 0; i < argc; i++)
    {
        printf("[%s]\n", argv[i]);
    }
};

typedef uint8_t (*device_test_callback_t)(int argc, char *argv[]);
typedef struct
{
    char *cmd;
    char *cmd_info;
    device_test_callback_t cb;
} device_test_t;

device_test_t device_testitem[] =
    {
        {"hh",
         "测试项目一",
         code_70},
};
void code_69()
{
    char *param[] = {"hh", "22"};
    int param_num = sizeof(param) / sizeof(param[0]);
    device_testitem[0].cb(param_num, param);
    return;
}
static void httpclient_base64enc(char *out, const char *in)
{
    const char code[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
    int i = 0, x = 0, l = 0;

    for (; *in; in++)
    {
        x = x << 8 | *in;
        for (l += 8; l >= 6; l -= 6)
        {
            out[i++] = code[(x >> (l - 6)) & 0x3f];
        }
    }
    if (l > 0)
    {
        x <<= 6 - l;
        out[i++] = code[x & 0x3f];
    }
    for (; i % 4;)
    {
        out[i++] = '=';
    }
    out[i] = '\0';
}

static const char base64_table[] =
    {
        'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
        'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
        'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
        'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
        'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
        'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
        '+', '/'};
unsigned char *base64_decode(const unsigned char *src, size_t len,
                             size_t *out_len)
{
    unsigned char dtable[256], *out, *pos, block[4], tmp;
    size_t i, count, olen;
    int pad = 0;

    memset(dtable, 0x80, 256);
    for (i = 0; i < sizeof(base64_table) - 1; i++)
        dtable[base64_table[i]] = (unsigned char)i;
    dtable['='] = 0;

    count = 0;
    for (i = 0; i < len; i++)
    {
        if (dtable[src[i]] != 0x80)
            count++;
    }

    if (count == 0 || count % 4)
        return NULL;

    olen = count / 4 * 3;
    pos = out = malloc(olen);
    if (out == NULL)
        return NULL;

    count = 0;
    for (i = 0; i < len; i++)
    {
        tmp = dtable[src[i]];
        if (tmp == 0x80)
            continue;

        if (src[i] == '=')
            pad++;
        block[count] = tmp;
        count++;
        if (count == 4)
        {
            *pos++ = (block[0] << 2) | (block[1] >> 4);
            *pos++ = (block[1] << 4) | (block[2] >> 2);
            *pos++ = (block[2] << 6) | block[3];
            count = 0;
            if (pad)
            {
                if (pad == 1)
                    pos--;
                else if (pad == 2)
                    pos -= 2;
                else
                {
                    /* Invalid padding */
                    free(out);
                    return NULL;
                }
                break;
            }
        }
    }

    *out_len = pos - out;
    return out;
}

void code_71()
{
    char *str[] = {"hh", "heiehi"};
    int len = sizeof(str) / sizeof(str[0]);
    for (int i = 0; i < len; i++)
    {
        printf("%s\n", str[i]);
    }

    uint8_t num = 1;
    printf(">>%d\n", num);

    char *base64_in = "dsadasddweewr4325224324';lm',;',ewt",
         base64_out[512] = {0};
    httpclient_base64enc(base64_out, base64_in);
    printf("%s\n%s\n", base64_in, base64_out);

    char *res = base64_decode(base64_out, strlen(base64_out), &len);
    printf("%s \n%d\n", res, len);
}

void code_72(int argc, char *argv[])
{
    printf("get mp3 file info\n");
    char *file_path = argv[1];
    if (strcmp(file_path, "-h") == 0)
    {
        printf("ex: getfilesize xxxx\n");
        return 0;
    }

    int file_name_len = strlen(argv[1]),
        dot_pos = 0;
    char file_type[20] = {0};

    for (int i = 0; i < 10; i++)
    {
        if (argv[1][file_name_len - i] == '.')
        {
            // printf("%d\n", i);
            break;
        }
        else
            dot_pos++;
    }

    memcpy(file_type, &argv[1][file_name_len - dot_pos], dot_pos);
    printf("file type[%s] \n", file_type);

    char *file_open_type = {"rb+"};
    FILE *f = fopen(file_path, file_open_type);

    while (1)
    {
        char c = fgetc(f);
        if (c == EOF)
        {
            break;
        }
        printf("%#x ", c);
    }

    // for (int i = 0; i < 5; i++)
    // {
    //     char buf[200] = {0};
    //     fgets(buf, sizeof(buf), f);
    //     printf("%s", buf);
    // }

    // fpos_t fpos = 100;
    // fsetpos(f, &fpos);

    // for (int i = 0; i < 10; i++)
    // {
    //     fputc(i, f);
    // }

    int file_size = 0;
    fseek(f, 0, SEEK_END);
    file_size = ftell(f);

    // fseek(f, 0, SEEK_SET);
    // for (int i = 0; i <= file_size; i++)
    // {
    //     fputc('c', f);
    // }

    printf("file size[%d]\n", file_size);

    printf("close file\n");
    fclose(f);
}

struct list_t
{
    struct list_t *list;
    char str[50];
    size_t size;
};

struct list_t *list = NULL;

struct list_t *list_add(struct list_t *ls)
{
    if (ls == NULL)
    {
        return NULL;
    }
    ls->list = malloc(sizeof(struct list_t));
    memset(ls->list, 0, sizeof(struct list_t));

    return ls->list;
}

struct list_t *list_del(struct list_t *ls)
{
    if (ls == NULL)
    {
        printf("free %s \n", ls->str);

        return NULL;
    }
    struct list_t *list_temp = ls;
    if (list_temp->list != NULL)
    {
        if (list_del(list_temp->list) == NULL)
        {
            printf("free %s %#x\n", list_temp->str, list_temp);

            free(list_temp);
            list_temp = NULL;
        }
        else
        {
            printf("free %s \n", list_temp->str);
        }
    }
    else
    {
        printf("free %s %#x\n", list_temp->str, list_temp);

        free(list_temp);
        list_temp = NULL;
    }

    return NULL;
}

int code_73()
{
    printf("list \n");
    list = (struct list_t *)malloc(sizeof(struct list_t));
    memset(list, 0, sizeof(struct list_t));
    if (list == NULL)
    {
        return 0;
    }
    printf("start %#x \n", list);

    struct list_t *list_temp = list;
    for (int i = 0; i < 10; i++)
    {

        list_temp = list_add(list_temp);
        if (list_temp != NULL)
        {
            sprintf(list_temp->str, "index %d", i);
            printf("%s %#x\n", list_temp->str, list_temp);
        }
    }

    list_del(list);

    printf("end %#x \n", list);
}

void code_74()
{
    printf("-----\n");

    char *str = "xx@13213@xx",
         buf[20] = {0};

    sscanf(str, " xx@%s@xx", buf);
    sscanf(buf, " %s@xx", buf);
    printf("---> %s\n", buf);
}

int main(int argc, char *argv[])
{

    uint8_t buf[20] = {0};
    printf("---> %s\n", buf);
    return 0;
}
